Script revisão


SUBMITTED BY: cleitongabriel

DATE: Dec. 18, 2023, 5:31 p.m.

UPDATED: Dec. 20, 2023, 6:52 p.m.

FORMAT: Text only

SIZE: 16.3 kB

HITS: 508

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import subprocess, os, random, string, sys, shutil, socket
  4. from itertools import cycle, izip
  5. rDownloadURL = {"main": "https://xtreamui.net/ck/main_xtreamcodes_reborn.tar.gz", "sub": "https://xtreamui.net/ck/sub_xtreamcodes_reborn.tar.gz"}
  6. rPackages = ["libcurl3", "libxslt1-dev", "libgeoip-dev", "e2fsprogs", "wget", "mcrypt", "nscd", "htop", "zip", "unzip", "mc", "mysql-server"]
  7. rInstall = {"MAIN": "main", "LB": "sub"}
  8. rMySQLCnf = "IyBYdHJlYW0gQ29kZXMKCltjbGllbnRdCnBvcnQgICAgICAgICAgICA9IDMzMDYKCltteXNxbGRfc2FmZV0KbmljZSAgICAgICAgICAgID0gMAoKW215c3FsZF0KdXNlciAgICAgICAgICAgID0gbXlzcWwKcG9ydCAgICAgICAgICAgID0gNzk5OQpiYXNlZGlyICAgICAgICAgPSAvdXNyCmRhdGFkaXIgICAgICAgICA9IC92YXIvbGliL215c3FsCnRtcGRpciAgICAgICAgICA9IC90bXAKbGMtbWVzc2FnZXMtZGlyID0gL3Vzci9zaGFyZS9teXNxbApza2lwLWV4dGVybmFsLWxvY2tpbmcKc2tpcC1uYW1lLXJlc29sdmU9MQoKYmluZC1hZGRyZXNzICAgICAgICAgICAgPSAqCmtleV9idWZmZXJfc2l6ZSA9IDEyOE0KCm15aXNhbV9zb3J0X2J1ZmZlcl9zaXplID0gNE0KbWF4X2FsbG93ZWRfcGFja2V0ICAgICAgPSA2NE0KbXlpc2FtLXJlY292ZXItb3B0aW9ucyA9IEJBQ0tVUAptYXhfbGVuZ3RoX2Zvcl9zb3J0X2RhdGEgPSA4MTkyCnF1ZXJ5X2NhY2hlX2xpbWl0ICAgICAgID0gNE0KcXVlcnlfY2FjaG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XplICAgICAgICAgICAgICA9IDE2TQo=".decode("base64")
  9. class col:
  10. HEADER = '\033[95m'
  11. OKBLUE = '\033[94m'
  12. OKGREEN = '\033[92m'
  13. WARNING = '\033[93m'
  14. FAIL = '\033[91m'
  15. ENDC = '\033[0m'
  16. BOLD = '\033[1m'
  17. UNDERLINE = '\033[4m'
  18. def generate(length=16): return ''.join(random.choice(string.ascii_letters + string.digits) for i in range(length))
  19. def getIP():
  20. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  21. s.connect(("8.8.8.8", 80))
  22. return s.getsockname()[0]
  23. def getVersion():
  24. try: return subprocess.check_output("lsb_release -d".split()).split(":")[-1].strip()
  25. except: return ""
  26. def printc(rText, rColour=col.OKBLUE, rPadding=0):
  27. print "%s ┌──────────────────────────────────────────┐ %s" % (rColour, col.ENDC)
  28. for i in range(rPadding): print "%s │ │ %s" % (rColour, col.ENDC)
  29. print "%s │ %s%s%s │ %s" % (rColour, " "*(20-(len(rText)/2)), rText, " "*(40-(20-(len(rText)/2))-len(rText)), col.ENDC)
  30. for i in range(rPadding): print "%s │ │ %s" % (rColour, col.ENDC)
  31. print "%s └──────────────────────────────────────────┘ %s" % (rColour, col.ENDC)
  32. print " "
  33. def prepare(rType="MAIN"):
  34. global rPackages
  35. if rType <> "MAIN": rPackages = rPackages[:-1]
  36. printc("Preparing Installation")
  37. for rFile in ["/var/lib/dpkg/lock-frontend", "/var/cache/apt/archives/lock", "/var/lib/dpkg/lock"]:
  38. try: os.remove(rFile)
  39. except: pass
  40. os.system("apt-get update > /dev/null")
  41. printc("Removing libcurl4 if installed")
  42. os.system("apt-get remove --auto-remove libcurl4 -y > /dev/null")
  43. for rPackage in rPackages:
  44. printc("Installing %s" % rPackage)
  45. os.system("apt-get install %s -y > /dev/null" % rPackage)
  46. printc("Installing libpng")
  47. os.system("wget -q -O /tmp/libpng12.deb https://xtreamui.net/ck/libpng12-0_1.2.54-1ubuntu1_amd64.deb")
  48. os.system("dpkg -i /tmp/libpng12.deb > /dev/null")
  49. os.system("apt-get install -y > /dev/null") # Clean up above
  50. try: os.remove("/tmp/libpng12.deb")
  51. except: pass
  52. try:
  53. subprocess.check_output("getent passwd xtreamcodes > /dev/null".split())
  54. except:
  55. # Create User
  56. printc("Creating user xtreamcodes")
  57. os.system("adduser --system --shell /bin/false --group --disabled-login xtreamcodes > /dev/null")
  58. if not os.path.exists("/home/xtreamcodes"): os.mkdir("/home/xtreamcodes")
  59. return True
  60. def install(rType="MAIN"):
  61. global rInstall, rDownloadURL
  62. printc("Downloading Software")
  63. try: rURL = rDownloadURL[rInstall[rType]]
  64. except:
  65. printc("Invalid download URL!", col.FAIL)
  66. return False
  67. os.system('wget -q -O "/tmp/xtreamcodes.tar.gz" "%s"' % rURL)
  68. if os.path.exists("/tmp/xtreamcodes.tar.gz"):
  69. printc("Installing Software")
  70. os.system('tar -zxvf "/tmp/xtreamcodes.tar.gz" -C "/home/xtreamcodes/" > /dev/null')
  71. try: os.remove("/tmp/xtreamcodes.tar.gz")
  72. except: pass
  73. return True
  74. printc("Failed to download installation file!", col.FAIL)
  75. return False
  76. def mysql(rUsername, rPassword):
  77. global rMySQLCnf
  78. printc("Configuring MySQL")
  79. rCreate = True
  80. if os.path.exists("/etc/mysql/my.cnf"):
  81. if open("/etc/mysql/my.cnf", "r").read(14) == "# Xtream Codes": rCreate = False
  82. if rCreate:
  83. shutil.copy("/etc/mysql/my.cnf", "/etc/mysql/my.cnf.xc")
  84. rFile = open("/etc/mysql/my.cnf", "w")
  85. rFile.write(rMySQLCnf)
  86. rFile.close()
  87. os.system("service mysql restart > /dev/null")
  88. printc("Enter MySQL Root Password:", col.WARNING)
  89. for i in range(5):
  90. rMySQLRoot = raw_input(" ")
  91. print " "
  92. if len(rMySQLRoot) > 0: rExtra = " -p%s" % rMySQLRoot
  93. else: rExtra = ""
  94. printc("Drop existing & create database? Y/N", col.WARNING)
  95. if raw_input(" ").upper() == "Y": rDrop = True
  96. else: rDrop = False
  97. try:
  98. if rDrop:
  99. os.system('mysql -u root%s -e "DROP DATABASE IF EXISTS xtream_iptvpro; CREATE DATABASE IF NOT EXISTS xtream_iptvpro;" > /dev/null' % rExtra)
  100. os.system("mysql -u root%s xtream_iptvpro < /home/xtreamcodes/iptv_xtream_codes/database.sql > /dev/null" % rExtra)
  101. 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)))
  102. 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()))
  103. 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)
  104. os.system('mysql -u root%s -e "GRANT ALL PRIVILEGES ON *.* TO \'%s\'@\'%%\' IDENTIFIED BY \'%s\' WITH GRANT OPTION; FLUSH PRIVILEGES;" > /dev/null' % (rExtra, rUsername, rPassword))
  105. try: os.remove("/home/xtreamcodes/iptv_xtream_codes/database.sql")
  106. except: pass
  107. return True
  108. except: printc("Invalid password! Try again", col.FAIL)
  109. return False
  110. def encrypt(rHost="127.0.0.1", rUsername="user_iptvpro", rPassword="", rDatabase="xtream_iptvpro", rServerID=1, rPort=7999):
  111. printc("Encrypting...")
  112. try: os.remove("/home/xtreamcodes/iptv_xtream_codes/config")
  113. except: pass
  114. rf = open('/home/xtreamcodes/iptv_xtream_codes/config', 'wb')
  115. 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', ''))
  116. rf.close()
  117. def configure():
  118. printc("Configuring System")
  119. if not "/home/xtreamcodes/iptv_xtream_codes/" in open("/etc/fstab").read():
  120. rFile = open("/etc/fstab", "a")
  121. 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")
  122. rFile.close()
  123. if not "xtreamcodes" in open("/etc/sudoers").read():
  124. os.system('echo "xtreamcodes ALL=(root) NOPASSWD: /sbin/iptables, /usr/bin/chattr" >> /etc/sudoers')
  125. if not os.path.exists("/etc/init.d/xtreamcodes"):
  126. rStart = open("/etc/init.d/xtreamcodes", "w")
  127. 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")
  128. rStart.close()
  129. os.system("chmod +x /etc/init.d/xtreamcodes")
  130. os.system("update-rc.d xtreamcodes defaults")
  131. os.system("update-rc.d xtreamcodes enable")
  132. try: os.remove("/usr/bin/ffmpeg")
  133. except: pass
  134. if not os.path.exists("/home/xtreamcodes/iptv_xtream_codes/tv_archive"): os.mkdir("/home/xtreamcodes/iptv_xtream_codes/tv_archive/")
  135. os.system("ln -s /home/xtreamcodes/iptv_xtream_codes/bin/ffmpeg /usr/bin/")
  136. os.system("chown xtreamcodes:xtreamcodes -R /home/xtreamcodes > /dev/null")
  137. os.system("chmod -R 0777 /home/xtreamcodes > /dev/null")
  138. os.system("chmod +x /home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
  139. os.system("chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null")
  140. os.system("mount -a")
  141. if not "api.xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 api.xtream-codes.com" >> /etc/hosts')
  142. if not "downloads.xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 downloads.xtream-codes.com" >> /etc/hosts')
  143. if not " xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 xtream-codes.com" >> /etc/hosts')
  144. os.system('apt-get install unzip e2fsprogs python-paramiko -y && chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb && rm -rf /home/xtreamcodes/iptv_xtream_codes/admin 2>/dev/null && rm -rf /home/xtreamcodes/iptv_xtream_codes/pytools 2>/dev/null && wget -q "https://xtreamui.net/ck/update.zip" -O /tmp/update.zip -o /dev/null && unzip /tmp/update.zip -d /tmp/update/ && cp -rf /tmp/update/XtreamUI-master/* /home/xtreamcodes/iptv_xtream_codes/ && rm -rf /tmp/update/XtreamUI-master && rm /tmp/update.zip && rm -rf /tmp/update && chown -R xtreamcodes:xtreamcodes /home/xtreamcodes/ && chmod +x /home/xtreamcodes/iptv_xtream_codes/permissions.sh && /home/xtreamcodes/iptv_xtream_codes/permissions.sh && find /home/xtreamcodes/ -type d -not \( -name .update -prune \) -exec chmod -R 777 {} +')
  145. os.system("sed -i 's|echo \"Xtream Codes Reborn\";|header(\"Location: https://www.google.com/\");|g' /home/xtreamcodes/iptv_xtream_codes/wwwdir/index.php")
  146. os.system("sudo wget -q https://xtreamui.net/ck/youtube-dl -O /usr/local/bin/youtube-dl")
  147. os.system("sudo chmod a+rx /usr/local/bin/youtube-dl")
  148. def start(first=True):
  149. if first: printc("Starting Xtream Codes")
  150. else: printc("Restarting Xtream Codes")
  151. os.system("/home/xtreamcodes/iptv_xtream_codes/start_services.sh 2>/dev/null")
  152. os.system("chattr +i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb")
  153. def modifyNginx():
  154. printc("Modifying Nginx")
  155. rPath = "/home/xtreamcodes/iptv_xtream_codes/nginx/conf/nginx.conf"
  156. rPrevData = open(rPath, "r").read()
  157. if not "listen 25500;" in rPrevData:
  158. shutil.copy(rPath, "%s.xc" % rPath)
  159. rData = "}".join(rPrevData.split("}")[:-1]) + "\n server {\n listen 25500;\n index index.php index.html index.htm;\n root /home/xtreamcodes/iptv_xtream_codes/admin/;\n\n location ~ \.php$ {\n limit_req zone=one burst=8;\n try_files $uri =404;\n fastcgi_index index.php;\n fastcgi_pass php;\n include fastcgi_params;\n fastcgi_buffering on;\n fastcgi_buffers 96 32k;\n fastcgi_buffer_size 32k;\n fastcgi_max_temp_file_size 0;\n fastcgi_keep_conn on;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi_param SCRIPT_NAME $fastcgi_script_name;\n }\n }\n#ISP CONFIGURATION\n\n server {\n listen 8805;\n root /home/xtreamcodes/iptv_xtream_codes/isp/;\n location / {\n allow 127.0.0.1;\n deny all;\n }\n location ~ \.php$ {\n limit_req zone=one burst=8;\n try_files $uri =404;\n fastcgi_index index.php;\n fastcgi_pass php;\n include fastcgi_params;\n fastcgi_buffering on;\n fastcgi_buffers 96 32k;\n fastcgi_buffer_size 32k;\n fastcgi_max_temp_file_size 0;\n fastcgi_keep_conn on;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi_param SCRIPT_NAME $fastcgi_script_name;\n }\n }\n}"
  160. rFile = open(rPath, "w")
  161. rFile.write(rData)
  162. rFile.close()
  163. if __name__ == "__main__":
  164. printc("CK41 MOD - Reborn by DRMStuff.com", col.OKGREEN, 2)
  165. rType = raw_input(" Installation Type [MAIN, LB]: ")
  166. print " "
  167. if rType.upper() in ["MAIN", "LB"]:
  168. if rType.upper() == "LB":
  169. rHost = raw_input(" Main Server IP Address: ")
  170. rPassword = raw_input(" MySQL Password: ")
  171. try: rServerID = int(raw_input(" Load Balancer Server ID: "))
  172. except: rServerID = -1
  173. print " "
  174. else:
  175. rHost = "127.0.0.1"
  176. rPassword = generate()
  177. rServerID = 1
  178. rUsername = "user_iptvpro"
  179. rDatabase = "xtream_iptvpro"
  180. rPort = 7999
  181. if len(rHost) > 0 and len(rPassword) > 0 and rServerID > -1:
  182. printc("Start installation? Y/N", col.WARNING)
  183. if raw_input(" ").upper() == "Y":
  184. print " "
  185. rRet = prepare(rType.upper())
  186. if not install(rType.upper()): sys.exit(1)
  187. if rType.upper() == "MAIN":
  188. if not mysql(rUsername, rPassword): sys.exit(1)
  189. encrypt(rHost, rUsername, rPassword, rDatabase, rServerID, rPort)
  190. configure()
  191. if rType.upper() == "MAIN": modifyNginx()
  192. start()
  193. printc("Xtream UI 22 CK41 MOD Reborn", col.OKGREEN, 2)
  194. printc("Admin UI: http://%s:25500" % getIP())
  195. if rType.upper() == "MAIN":
  196. printc("Please store your MySQL password!")
  197. printc(rPassword)
  198. else: printc("Installation cancelled", col.FAIL)
  199. else: printc("Invalid entries", col.FAIL)
  200. else: printc("Invalid installation type", col.FAIL)

comments powered by Disqus