Install24.py


SUBMITTED BY: cleitongabriel

DATE: Sept. 2, 2024, 4:54 a.m.

FORMAT: Text only

SIZE: 25.9 kB

HITS: 170

  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. import subprocess, os, random, string, sys, shutil, socket, zipfile, urllib.request, urllib.error, urllib.parse, json, base64
  4. from itertools import cycle
  5. from zipfile import ZipFile
  6. from urllib.request import Request, urlopen
  7. from urllib.error import URLError, HTTPError
  8. rDownloadURL = {"main": "https://bitbucket.org/masoudgb/xtream-ui/raw/master/main_xui_masoudgb.zip", "sub": "https://bitbucket.org/masoudgb/xtream-ui/raw/master/sub_xui_masoudgb.zip"}
  9. import os
  10. rPackages = ["libcurl4", "libxslt1-dev", "libgeoip-dev", "libonig-dev", "e2fsprogs", "wget", "mcrypt", "nscd", "htop", "zip", "unzip", "mc", "mariadb-server", "libpng16-16", "python3-paramiko", "python-is-python3"]
  11. rInstall = {"MAIN": "main", "LB": "sub"}
  12. rUpdate = {"UPDATE": "update"}
  13. rMySQLCnf = base64.b64decode("IyBYdHJlYW0gQ29kZXMKCltjbGllbnRdCnBvcnQgICAgICAgICAgICA9IDMzMDYKCltteXNxbGRfc2FmZV0KbmljZSAgICAgICAgICAgID0gMAoKW215c3FsZF0KdXNlciAgICAgICAgICAgID0gbXlzcWwKcG9ydCAgICAgICAgICAgID0gNzk5OQpiYXNlZGlyICAgICAgICAgPSAvdXNyCmRhdGFkaXIgICAgICAgICA9IC92YXIvbGliL215c3FsCnRtcGRpciAgICAgICAgICA9IC90bXAKbGMtbWVzc2FnZXMtZGlyID0gL3Vzci9zaGFyZS9teXNxbApza2lwLWV4dGVybmFsLWxvY2tpbmcKc2tpcC1uYW1lLXJlc29sdmU9MQoKYmluZC1hZGRyZXNzICAgICAgICAgICAgPSAqCmtleV9idWZmZXJfc2l6ZSA9IDEyOE0KCm15aXNhbV9zb3J0X2J1ZmZlcl9zaXplID0gNE0KbWF4X2FsbG93ZWRfcGFja2V0ICAgICAgPSA2NE0KbXlpc2FtLXJlY292ZXItb3B0aW9ucyA9IEJBQ0tVUAptYXhfbGVuZ3RoX2Zvcl9zb3J0X2RhdGEgPSA4MTkyCnF1ZXJ5X2NhY2hlX2xpbWl0ICAgICAgID0gNE0KcXVlcnlfY2FjaGVfc2l6ZSAgICAgICAgPSAwCnF1ZXJ5X2NhY2hlX3R5cGUJPSAwCgpleHBpcmVfbG9nc19kYXlzICAgICAgICA9IDEwCm1heF9iaW5sb2dfc2l6ZSAgICAgICAgID0gMTAwTQoKbWF4X2Nvbm5lY3Rpb25zICA9IDIwMDAgI3JlY29tbWVuZGVkIGZvciAxNkdCIHJhbSAKYmFja19sb2cgPSA0MDk2Cm9wZW5fZmlsZXNfbGltaXQgPSAxNjM4NAppbm5vZGJfb3Blbl9maWxlcyA9IDE2Mzg0Cm1heF9jb25uZWN0X2Vycm9ycyA9IDMwNzIKdGFibGVfb3Blbl9jYWNoZSA9IDQwOTYKdGFibGVfZGVmaW5pdGlvbl9jYWNoZSA9IDQwOTYKCgp0bXBfdGFibGVfc2l6ZSA9IDFHCm1heF9oZWFwX3RhYmxlX3NpemUgPSAxRwoKaW5ub2RiX2J1ZmZlcl9wb29sX3NpemUgPSAxMkcgI3JlY29tbWVuZGVkIGZvciAxNkdCIHJhbQppbm5vZGJfYnVmZmVyX3Bvb2xfaW5zdGFuY2VzID0gMQppbm5vZGJfcmVhZF9pb190aHJlYWRzID0gNjQKaW5ub2RiX3dyaXRlX2lvX3RocmVhZHMgPSA2NAppbm5vZGJfdGhyZWFkX2NvbmN1cnJlbmN5ID0gMAppbm5vZGJfZmx1c2hfbG9nX2F0X3RyeF9jb21taXQgPSAwCmlubm9kYl9mbHVzaF9tZXRob2QgPSBPX0RJUkVDVApwZXJmb3JtYW5jZV9zY2hlbWEgPSBPTgppbm5vZGItZmlsZS1wZXItdGFibGUgPSAxCmlubm9kYl9pb19jYXBhY2l0eT0yMDAwMAppbm5vZGJfdGFibGVfbG9ja3MgPSAwCmlubm9kYl9sb2NrX3dhaXRfdGltZW91dCA9IDAKaW5ub2RiX2RlYWRsb2NrX2RldGVjdCA9IDAKaW5ub2RiX2xvZ19maWxlX3NpemUgPSA1MTJNCgpzcWwtbW9kZT0iTk9fRU5HSU5FX1NVQlNUSVRVVElPTiIKCltteXNxbGR1bXBdCnF1aWNrCnF1b3RlLW5hbWVzCm1heF9hbGxvd2VkX3BhY2tldCAgICAgID0gMTZNCgpbbXlzcWxdCgpbaXNhbWNoa10Ka2V5X2J1ZmZlcl9zaXplICAgICAgICAgICAgICA9IDE2TQo=")
  14. rVersions = {
  15. "24.04": "noble"
  16. }
  17. class col:
  18. BLACK = '\033[30m'
  19. RED = '\033[31m'
  20. GREEN = '\033[32m'
  21. YELLOW = '\033[33m'
  22. BLUE = '\033[34m'
  23. MAGENTA = '\033[35m'
  24. CYAN = '\033[36m'
  25. LIGHT_GRAY = '\033[37m'
  26. DARK_GRAY = '\033[90m'
  27. BRIGHT_RED = '\033[91m'
  28. BRIGHT_GREEN = '\033[92m'
  29. BRIGHT_YELLOW = '\033[93m'
  30. BRIGHT_BLUE = '\033[94m'
  31. BRIGHT_MAGENTA = '\033[95m'
  32. BRIGHT_CYAN = '\033[96m'
  33. WHITE = '\033[97m'
  34. BOLD = '\033[1m'
  35. UNDERLINE = '\033[4m'
  36. ENDC = '\033[0m'
  37. def generate(length=19): return ''.join(random.choice(string.ascii_letters + string.digits) for i in range(length))
  38. def getIP():
  39. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  40. s.connect(("8.8.8.8", 80))
  41. return s.getsockname()[0]
  42. def getVersion():
  43. try: return os.popen("lsb_release -d").read().split(":")[-1].strip()
  44. except: return ""
  45. def printc(rText, rColour=col.BRIGHT_GREEN, rPadding=0, rLimit=46):
  46. print("%s ┌─────────────────────────────────────────────────┐ %s" % (rColour, col.ENDC))
  47. for i in range(rPadding): print("%s │ │ %s" % (rColour, col.ENDC))
  48. array = [rText[i:i+rLimit] for i in range(0, len(rText), rLimit)]
  49. for i in array : print("%s │ %s%s%s │ %s" % (rColour, " "*round(23-(len(i)/2)), i, " "*round(46-(22-(len(i)/2))-len(i)), col.ENDC))
  50. for i in range(rPadding): print("%s │ │ %s" % (rColour, col.ENDC))
  51. print("%s └─────────────────────────────────────────────────┘ %s" % (rColour, col.ENDC))
  52. print(" ")
  53. def is_installed(package_name):
  54. try:
  55. subprocess.run(['dpkg', '-s', package_name], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  56. return True
  57. except subprocess.CalledProcessError:
  58. return False
  59. def prepare(rType="MAIN"):
  60. global rPackages
  61. if rType != "MAIN":
  62. rPackages = rPackages[:-1]
  63. printc("Preparing Installation")
  64. if os.path.isfile('/home/xtreamcodes/iptv_xtream_codes/config'):
  65. shutil.copyfile('/home/xtreamcodes/iptv_xtream_codes/config', '/tmp/config.xtmp')
  66. if os.path.isfile('/home/xtreamcodes/iptv_xtream_codes/config'):
  67. os.system('chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null')
  68. for rFile in ["/var/lib/dpkg/lock-frontend", "/var/cache/apt/archives/lock", "/var/lib/dpkg/lock"]:
  69. try:
  70. os.remove(rFile)
  71. except FileNotFoundError:
  72. pass
  73. printc("Updating Operating System")
  74. subprocess.run("apt-get update -y > /dev/null 2>&1", shell=True)
  75. subprocess.run("apt-get -y full-upgrade > /dev/null 2>&1", shell=True)
  76. if rType == "MAIN":
  77. printc("Install MariaDB 11.5 repository")
  78. subprocess.run("apt-get install -y software-properties-common > /dev/null 2>&1", shell=True)
  79. subprocess.run("curl -fsSL https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor -o /usr/share/keyrings/mariadb-archive-keyring.gpg > /dev/null 2>&1", shell=True)
  80. subprocess.run(
  81. "echo y | sudo add-apt-repository -y 'deb [arch=amd64,arm64,ppc64el,s390x] [signed-by=/usr/share/keyrings/mariadb-archive-keyring.gpg] https://mirrors.xtom.com/mariadb/repo/11.5/ubuntu noble main' > /dev/null 2>&1",
  82. shell=True
  83. )
  84. subprocess.run("apt-get update -y > /dev/null 2>&1", shell=True)
  85. for rPackage in rPackages:
  86. if not is_installed(rPackage):
  87. printc(f"Installing {rPackage}")
  88. subprocess.run(f"apt-get install {rPackage} -y > /dev/null 2>&1", shell=True)
  89. if not is_installed("libssl1.1"):
  90. printc("Installing libssl1.1")
  91. subprocess.run("wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb > /dev/null 2>&1 && sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb > /dev/null 2>&1 && rm -rf libssl1.1_1.1.0g-2ubuntu4_amd64.deb > /dev/null 2>&1", shell=True)
  92. if not is_installed("libzip5"):
  93. printc("Installing libzip5")
  94. subprocess.run("wget http://archive.ubuntu.com/ubuntu/pool/universe/libz/libzip/libzip5_1.5.1-0ubuntu1_amd64.deb > /dev/null 2>&1 && sudo dpkg -i libzip5_1.5.1-0ubuntu1_amd64.deb > /dev/null 2>&1 && rm -rf libzip5_1.5.1-0ubuntu1_amd64.deb > /dev/null 2>&1", shell=True)
  95. subprocess.run("sudo apt-get install -f -y > /dev/null 2>&1", shell=True)
  96. python_installed = is_installed("python2.7")
  97. pip_installed = subprocess.run("pip2.7 --version > /dev/null 2>&1", shell=True).returncode == 0
  98. paramiko_installed = subprocess.run("pip2.7 show paramiko > /dev/null 2>&1", shell=True).returncode == 0
  99. if not python_installed or not pip_installed or not paramiko_installed:
  100. printc("Installing python2 & pip2 & paramiko...")
  101. subprocess.run("sudo apt install -y build-essential checkinstall libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev wget tar > /dev/null 2>&1", shell=True)
  102. if not python_installed:
  103. subprocess.run("cd /usr/src && sudo wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz > /dev/null 2>&1 && sudo tar xzf Python-2.7.18.tgz > /dev/null 2>&1 && cd Python-2.7.18 && sudo ./configure --enable-optimizations > /dev/null 2>&1 && sudo make altinstall > /dev/null 2>&1", shell=True)
  104. if not pip_installed:
  105. subprocess.run("curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py > /dev/null 2>&1 && sudo python2.7 get-pip.py > /dev/null 2>&1", shell=True)
  106. if not paramiko_installed:
  107. subprocess.run("pip2.7 install paramiko > /dev/null 2>&1", shell=True)
  108. subprocess.run("apt-get install -f -y > /dev/null 2>&1", shell=True)
  109. try:
  110. subprocess.run("getent passwd xtreamcodes > /dev/null 2>&1", shell=True, check=True)
  111. except subprocess.CalledProcessError:
  112. printc("Creating user xtreamcodes")
  113. subprocess.run("adduser --system --shell /bin/false --group --disabled-login xtreamcodes > /dev/null 2>&1", shell=True)
  114. if not os.path.exists("/home/xtreamcodes"):
  115. os.mkdir("/home/xtreamcodes")
  116. return True
  117. def install(rType="MAIN"):
  118. global rInstall, rDownloadURL
  119. printc("Downloading Software")
  120. try:
  121. rURL = rDownloadURL[rInstall[rType]]
  122. except KeyError:
  123. printc("Invalid download URL!", col.BRIGHT_RED)
  124. return False
  125. zip_file_path = "/tmp/xtreamcodes.zip"
  126. try:
  127. subprocess.run(['wget', '-q', '-O', zip_file_path, rURL], check=True)
  128. except subprocess.CalledProcessError:
  129. printc("Failed to download installation file!", col.BRIGHT_RED)
  130. return False
  131. if os.path.exists(zip_file_path):
  132. printc("Installing Software")
  133. try:
  134. with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
  135. zip_ref.extractall("/home/xtreamcodes/")
  136. except zipfile.BadZipFile:
  137. printc(f"Error: {zip_file_path} is not a valid zip file!", col.BRIGHT_RED)
  138. return False
  139. try:
  140. os.remove(zip_file_path)
  141. except OSError as e:
  142. printc(f"Error removing file {zip_file_path}: {e.strerror}")
  143. return True
  144. printc("Failed to download installation file!", col.BRIGHT_RED)
  145. return False
  146. def update(rType="MAIN"):
  147. if rType == "UPDATE":
  148. rlink = "https://bitbucket.org/masoudgb/xtream-ui/raw/master/update.zip"
  149. else:
  150. rlink = "https://bitbucket.org/masoudgb/xtream-ui/raw/master/release_22f.zip"
  151. printc("Downloading Software Update")
  152. os.system('wget -q -O "/tmp/update.zip" "%s"' % rlink)
  153. if os.path.exists("/tmp/update.zip"):
  154. try: is_ok = zipfile.ZipFile("/tmp/update.zip")
  155. except:
  156. printc("Invalid link or zip file is corrupted!", col.BRIGHT_RED)
  157. os.remove("/tmp/update.zip")
  158. return False
  159. rURL = rlink
  160. printc("Installing Admin Panel")
  161. if os.path.exists("/tmp/update.zip"):
  162. try: is_ok = zipfile.ZipFile("/tmp/update.zip")
  163. except:
  164. printc("Invalid link or zip file is corrupted!", col.BRIGHT_RED)
  165. os.remove("/tmp/update.zip")
  166. return False
  167. printc("Updating Software")
  168. os.system('chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null && rm -rf /home/xtreamcodes/iptv_xtream_codes/admin > /dev/null && rm -rf /home/xtreamcodes/iptv_xtream_codes/pytools > /dev/null && unzip /tmp/update.zip -d /tmp/update/ > /dev/null && cp -rf /tmp/update/XtreamUI-master/* /home/xtreamcodes/iptv_xtream_codes/ > /dev/null && rm -rf /tmp/update/XtreamUI-master > /dev/null && rm -rf /tmp/update > /dev/null && chown -R xtreamcodes:xtreamcodes /home/xtreamcodes/ > /dev/null && chmod +x /home/xtreamcodes/iptv_xtream_codes/permissions.sh > /dev/null && chattr +i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null')
  169. if not "sudo chmod 400 /home/xtreamcodes/iptv_xtream_codes/config" in open("/home/xtreamcodes/iptv_xtream_codes/permissions.sh").read(): os.system('echo "#!/bin/bash\nsudo chmod -R 777 /home/xtreamcodes 2>/dev/null\nsudo find /home/xtreamcodes/iptv_xtream_codes/admin/ -type f -exec chmod 644 {} \\; 2>/dev/null\nsudo find /home/xtreamcodes/iptv_xtream_codes/admin/ -type d -exec chmod 755 {} \\; 2>/dev/null\nsudo find /home/xtreamcodes/iptv_xtream_codes/wwwdir/ -type f -exec chmod 644 {} \\; 2>/dev/null\nsudo find /home/xtreamcodes/iptv_xtream_codes/wwwdir/ -type d -exec chmod 755 {} \\; 2>/dev/null\nsudo chmod +x /home/xtreamcodes/iptv_xtream_codes/nginx/sbin/nginx 2>/dev/null\nsudo chmod +x /home/xtreamcodes/iptv_xtream_codes/nginx_rtmp/sbin/nginx_rtmp 2>/dev/null\nsudo chmod 400 /home/xtreamcodes/iptv_xtream_codes/config 2>/dev/null" > /home/xtreamcodes/iptv_xtream_codes/permissions.sh')
  170. os.system("/home/xtreamcodes/iptv_xtream_codes/permissions.sh > /dev/null")
  171. try: os.remove("/tmp/update.zip")
  172. except: pass
  173. return True
  174. printc("Failed to download installation file!", col.BRIGHT_RED)
  175. return False
  176. def mysql(rUsername, rPassword):
  177. global rMySQLCnf
  178. printc("Configuring MySQL")
  179. rCreate = True
  180. if os.path.exists("/etc/mysql/my.cnf"):
  181. if open("/etc/mysql/my.cnf", "r").read(14) == "# Xtream Codes": rCreate = False
  182. if rCreate:
  183. shutil.copy("/etc/mysql/my.cnf", "/etc/mysql/my.cnf.xc")
  184. rFile = open("/etc/mysql/my.cnf", "wb")
  185. rFile.write(rMySQLCnf)
  186. rFile.close()
  187. os.system("systemctl restart mariadb > /dev/null")
  188. #printc("Enter MySQL Root Password:", col.BRIGHT_RED)
  189. for i in range(5):
  190. rMySQLRoot = "" #raw_input(" ")
  191. print(" ")
  192. if len(rMySQLRoot) > 0: rExtra = " -p%s" % rMySQLRoot
  193. else: rExtra = ""
  194. rDrop = True
  195. try:
  196. if rDrop:
  197. os.system('mysql -u root%s -e "DROP DATABASE IF EXISTS xtream_iptvpro; CREATE DATABASE IF NOT EXISTS xtream_iptvpro;" > /dev/null' % rExtra)
  198. os.system('mysql -u root%s -e "USE xtream_iptvpro; DROP USER IF EXISTS \'%s\'@\'%%\';" > /dev/null' % (rExtra, rUsername))
  199. os.system("mysql -u root%s xtream_iptvpro < /home/xtreamcodes/iptv_xtream_codes/database.sql > /dev/null" % rExtra)
  200. os.system('mysql -u root%s -e "USE xtream_iptvpro; UPDATE settings SET live_streaming_pass = \'%s\', unique_id = \'%s\', crypt_load_balancing = \'%s\';" > /dev/null' % (rExtra, generate(20), generate(10), generate(20)))
  201. os.system('mysql -u root%s -e "USE xtream_iptvpro; REPLACE INTO streaming_servers (id, server_name, domain_name, server_ip, vpn_ip, ssh_password, ssh_port, diff_time_main, http_broadcast_port, total_clients, system_os, network_interface, latency, status, enable_geoip, geoip_countries, last_check_ago, can_delete, server_hardware, total_services, persistent_connections, rtmp_port, geoip_type, isp_names, isp_type, enable_isp, boost_fpm, http_ports_add, network_guaranteed_speed, https_broadcast_port, https_ports_add, whitelist_ips, watchdog_data, timeshift_only) VALUES (1, \'Main Server\', \'\', \'%s\', \'\', NULL, NULL, 0, 25461, 1000, \'%s\', \'eth0\', 0, 1, 0, \'\', 0, 0, \'{}\', 3, 0, 25462, \'low_priority\', \'\', \'low_priority\', 0, 1, \'\', 1000, 25463, \'\', \'[\"127.0.0.1\",\"\"]\', \'{}\', 0);" > /dev/null' % (rExtra, getIP(), getVersion()))
  202. os.system('mysql -u root%s -e "USE xtream_iptvpro; REPLACE INTO reg_users (id, username, password, email, member_group_id, verified, status) VALUES (1, \'admin\', \'\\$6\\$rounds=20000\\$xtreamcodes\\$XThC5OwfuS0YwS4ahiifzF14vkGbGsFF1w7ETL4sRRC5sOrAWCjWvQJDromZUQoQuwbAXAFdX3h3Cp3vqulpS0\', \'admin@website.com\', 1, 1, 1);" > /dev/null' % rExtra)
  203. os.system('mysql -u root%s -e "CREATE USER \'%s\'@\'%%\' IDENTIFIED BY \'%s\'; GRANT ALL PRIVILEGES ON xtream_iptvpro.* TO \'%s\'@\'%%\' WITH GRANT OPTION; GRANT SELECT, LOCK TABLES ON *.* TO \'%s\'@\'%%\';FLUSH PRIVILEGES;" > /dev/null' % (rExtra, rUsername, rPassword, rUsername, rUsername))
  204. os.system('mysql -u root%s -e "USE xtream_iptvpro; CREATE TABLE IF NOT EXISTS dashboard_statistics (id int(11) NOT NULL AUTO_INCREMENT, type varchar(16) NOT NULL DEFAULT \'\', time int(16) NOT NULL DEFAULT \'0\', count int(16) NOT NULL DEFAULT \'0\', PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO dashboard_statistics (type, time, count) VALUES(\'conns\', UNIX_TIMESTAMP(), 0),(\'users\', UNIX_TIMESTAMP(), 0);\" > /dev/null' % rExtra)
  205. try: os.remove("/home/xtreamcodes/iptv_xtream_codes/database.sql")
  206. except: pass
  207. return True
  208. except: printc("Invalid password! Try again", col.BRIGHT_RED)
  209. return False
  210. def encrypt(rHost="127.0.0.1", rUsername="user_iptvpro", rPassword="", rDatabase="xtream_iptvpro", rServerID=1, rPort=7999):
  211. if os.path.isfile('/home/xtreamcodes/iptv_xtream_codes/config'):
  212. rDecrypt = decrypt()
  213. rHost = rDecrypt["host"]
  214. rPassword = rDecrypt["db_pass"]
  215. rServerID = int(rDecrypt["server_id"])
  216. rUsername = rDecrypt["db_user"]
  217. rDatabase = rDecrypt["db_name"]
  218. rPort = int(rDecrypt["db_port"])
  219. printc("Encrypting...")
  220. try: os.remove("/home/xtreamcodes/iptv_xtream_codes/config")
  221. except: pass
  222. rf = open('/home/xtreamcodes/iptv_xtream_codes/config', 'wb')
  223. 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')))
  224. rf.write(base64.b64encode(bytes(lestring, 'ascii')))
  225. rf.close()
  226. def decrypt():
  227. rConfigPath = "/home/xtreamcodes/iptv_xtream_codes/config"
  228. try: return json.loads(''.join(chr(c^ord(k)) for c,k in zip(base64.b64decode(open(rConfigPath, 'rb').read()), cycle('5709650b0d7806074842c6de575025b1'))))
  229. except: return None
  230. def configure():
  231. printc("Configuring System")
  232. if not "/home/xtreamcodes/iptv_xtream_codes/" in open("/etc/fstab").read():
  233. rFile = open("/etc/fstab", "a")
  234. 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")
  235. rFile.close()
  236. if not "xtreamcodes" in open("/etc/sudoers").read():
  237. os.system('echo "xtreamcodes ALL = (root) NOPASSWD: /sbin/iptables, /usr/bin/chattr" >> /etc/sudoers')
  238. if not os.path.exists("/etc/init.d/xtreamcodes"):
  239. rFile = open("/etc/init.d/xtreamcodes", "w")
  240. rFile.write("#! /bin/bash\n/home/xtreamcodes/iptv_xtream_codes/start_services.sh")
  241. rFile.close()
  242. os.system("chmod +x /etc/init.d/xtreamcodes > /dev/null")
  243. os.system("systemctl daemon-reload > /dev/null")
  244. try: os.remove("/usr/bin/ffmpeg")
  245. except: pass
  246. if not os.path.exists("/home/xtreamcodes/iptv_xtream_codes/tv_archive"): os.mkdir("/home/xtreamcodes/iptv_xtream_codes/tv_archive/")
  247. os.system("ln -s /home/xtreamcodes/iptv_xtream_codes/bin/ffmpeg /usr/bin/")
  248. if not os.path.exists("/home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb"): os.system("wget -q https://bitbucket.org/masoudgb/xtream-ui/raw/master/GeoLite2.mmdb -O /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb")
  249. if not os.path.exists("/home/xtreamcodes/iptv_xtream_codes/crons/pid_monitor.php"): os.system("wget -q https://bitbucket.org/masoudgb/xtream-ui/raw/master/pid_monitor.php -O /home/xtreamcodes/iptv_xtream_codes/crons/pid_monitor.php")
  250. os.system("chown xtreamcodes:xtreamcodes -R /home/xtreamcodes > /dev/null")
  251. os.system("chmod -R 0777 /home/xtreamcodes > /dev/null")
  252. os.system("chattr -ai /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null")
  253. os.system("sudo chmod 0777 /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null")
  254. 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")
  255. os.system("chmod +x /home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
  256. os.system("mount -a")
  257. os.system("chmod 0700 /home/xtreamcodes/iptv_xtream_codes/config > /dev/null")
  258. os.system("sed -i 's|echo \"Xtream Codes Reborn\";|header(\"Location: https://www.google.com/\");|g' /home/xtreamcodes/iptv_xtream_codes/wwwdir/index.php")
  259. if not "api.xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 api.xtream-codes.com" >> /etc/hosts')
  260. if not "downloads.xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 downloads.xtream-codes.com" >> /etc/hosts')
  261. if not "xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 xtream-codes.com" >> /etc/hosts')
  262. 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')
  263. def start(first=True):
  264. if first: printc("Starting Xtream Codes")
  265. else: printc("Restarting Xtream Codes")
  266. os.system("/home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
  267. def modifyNginx():
  268. printc("Modifying Nginx")
  269. rPath = "/home/xtreamcodes/iptv_xtream_codes/nginx/conf/nginx.conf"
  270. rPrevData = open(rPath, "r").read()
  271. if "listen 25500;" not in rPrevData:
  272. shutil.copy(rPath, f"{rPath}.xc")
  273. new_server_block = """
  274. server {
  275. listen 25500;
  276. index index.php index.html index.htm;
  277. root /home/xtreamcodes/iptv_xtream_codes/admin/;
  278. location ~ \\.php$ {
  279. limit_req zone=one burst=8;
  280. try_files $uri =404;
  281. fastcgi_index index.php;
  282. fastcgi_pass php;
  283. include fastcgi_params;
  284. fastcgi_buffering on;
  285. fastcgi_buffers 96 32k;
  286. fastcgi_buffer_size 32k;
  287. fastcgi_max_temp_file_size 0;
  288. fastcgi_keep_conn on;
  289. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  290. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  291. }
  292. }
  293. """
  294. http_start_index = rPrevData.find("http {")
  295. if http_start_index != -1:
  296. http_end_index = rPrevData.rfind("}", http_start_index)
  297. rData = rPrevData[:http_end_index] + new_server_block + "\n}" + rPrevData[http_end_index+1:]
  298. with open(rPath, "w") as rFile:
  299. rFile.write(rData)
  300. if __name__ == "__main__":
  301. try: rVersion = os.popen('lsb_release -sr').read().strip()
  302. except: rVersion = None
  303. if not rVersion in rVersions:
  304. printc("It can only be installed on Ubuntu 24.04")
  305. sys.exit(1)
  306. printc("X-UI installer in Ubuntu %s - Masoud-Gb" % rVersion, col.GREEN, 2)
  307. print(" ")
  308. rType = input(" Installation Type [MAIN, LB, UPDATE]: ")
  309. print(" ")
  310. if rType.upper() in ["MAIN", "LB"]:
  311. if rType.upper() == "LB":
  312. rHost = input(" Main Server IP Address: ")
  313. rPassword = input(" MySQL Password: ")
  314. try: rServerID = int(input(" Load Balancer Server ID: "))
  315. except: rServerID = -1
  316. print(" ")
  317. else:
  318. rHost = "127.0.0.1"
  319. rPassword = generate()
  320. rServerID = 1
  321. rUsername = "user_iptvpro"
  322. rDatabase = "xtream_iptvpro"
  323. rPort = 7999
  324. if len(rHost) > 0 and len(rPassword) > 0 and rServerID > -1:
  325. printc("Start installation? Y/N", col.BRIGHT_YELLOW)
  326. if input(" ").upper() == "Y":
  327. print(" ")
  328. rRet = prepare(rType.upper())
  329. if not install(rType.upper()): sys.exit(1)
  330. if rType.upper() == "MAIN":
  331. if not mysql(rUsername, rPassword): sys.exit(1)
  332. encrypt(rHost, rUsername, rPassword, rDatabase, rServerID, rPort)
  333. configure()
  334. if rType.upper() == "MAIN":
  335. modifyNginx()
  336. update(rType.upper())
  337. start()
  338. printc("Installation completed!", col.GREEN, 2)
  339. if rType.upper() == "MAIN":
  340. printc("Please store your MySQL password: %s" % rPassword, col.BRIGHT_YELLOW)
  341. printc("Admin UI Wan IP: http://%s:25500" % getIP(), col.BRIGHT_YELLOW)
  342. printc("Admin UI default login is admin/admin", col.BRIGHT_YELLOW)
  343. printc("Save Credentials is file to /root/credentials.txt", col.BRIGHT_YELLOW)
  344. rFile = open("/root/credentials.txt", "w")
  345. rFile.write("MySQL password: %s\n" % rPassword)
  346. rFile.write("Admin UI Wan IP: http://%s:25500\n" % getIP())
  347. rFile.write("Admin UI default login is admin/admin\n")
  348. rFile.close()
  349. else: printc("Installation cancelled", col.BRIGHT_RED)
  350. else: printc("Invalid entries", col.BRIGHT_RED)
  351. elif rType.upper() == "UPDATE":
  352. if os.path.exists("/home/xtreamcodes/iptv_xtream_codes/wwwdir/api.php"):
  353. printc("Update To Xtream-UI CKMOD 41 ? Y/N?", col.BRIGHT_YELLOW)
  354. if input(" ").upper() == "Y":
  355. if not update(rType.upper()): sys.exit(1)
  356. printc("Installation completed!", col.GREEN, 2)
  357. start()
  358. else: printc("Install Xtream Codes Main first!", col.BRIGHT_RED)
  359. else: printc("Invalid installation type", col.BRIGHT_RED)

comments powered by Disqus