#!/usr/bin/python
# -*- codificação: utf-8 -*-
importar subprocesso, os, random, string, sys, shutil, socket
do ciclo de importação do itertools, izip
rDownloadURL = {"principal": "https://xtreamui.net/ck/main_xtreamcodes_reborn.tar.gz", "sub": "https://xtreamui.net/ck/sub_xtreamcodes_reborn.tar.gz" }
rPackages = ["libcurl3", "libxslt1-dev", "libgeoip-dev", "e2fsprogs", "wget", "mcrypt", "nscd", "htop", "zip" ;, "descompactar", "mc", "servidor mysql"]
rInstall = {"MAIN": "principal", "LB": "sub"}
rMySQLCnf = "IyBYdHJlYW0gQ29kZXMKCltjbGllbnRdCnBvcnQgICAgICAgICAgICA9IDMzMDYKCltteXNxbGRfc2FmZV0KbmljZSAgICAgICAgICAgID0gMAoKW215c3FsZF0KdXNlciAgICAgICAgICAgID0gbX lzcWwKcG9ydCAgICAgICAgICAgID0gNzk5OQpiYXNlZGlyICAgICAgICAgPSAvdXNyCmRhdGFkaXIgICAgICAgICA9IC92YXIvbGliL215c3FsCnRtcGRpciAgICAgICAgICA9IC90bXAKbGMtbWVzc2FnZXMtZGlyID 0gL3Vzci9zaGFyZS9teXNxbApza2lwLWV4dGVybmFsLWxvY2tpbmcKc2tpcC1uYW1lLXJlc29sdmU9MQoKYmluZC1hZGRyZXNzICAgICAgICAgICAgPSAqCmtleV9idWZmZXJfc2l6ZSA9IDEyOE0KC m15aXNhbV9zb3J0X2J1ZmZlcl9zaXplID0gNE0KbWF4X2FsbG93ZWRfcGFja2V0ICAgICAgPSA2NE0KbXlpc2FtLXJlY292ZXItb3B0aW9ucyA9IEJBQ0tVUAptYXhfbGVuZ3RoX2Zvcl9zb3J0X2 RhdGEgPSA4MTkyCnF1ZXJ5X2NhY2hlX2xpbWl0ICAgICAgID0gNE0KcXVlcnlfY2FjaGVfc2l6ZSAgICAgICAgPSAyNTZNCgoKZXhwaXJlX2xvZ3NfZGF5cyAgICAgICAgPSAxMAptYXhfYmlubG9nX3NpemUgICAgICA gICA9IDEwME0KCm1heF9jb25uZWN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[91m'
ENDC = '\033[0m'
NEGRO = '\033[1m'
SUBLINHADO = '\033[4m'
def gerar (comprimento = 16): retornar ''.join (random.choice (string.ascii_letters + string.digits) para i no intervalo (comprimento))
def getIP():
s = soquete.socket(socket.AF_INET, soquete.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
retornar s.getsockname()[0]
def getVersão():
tente: return subprocess.check_output("lsb_release -d".split()).split(":")[-1].strip()
exceto: retornar "
def printc(rText, rColour=col.OKBLUE, rPadding=0):
imprimir "%s ┌────────────────────────────────────── ────┐% é" % (rCor, col.ENDC)
para i no intervalo (rPadding): imprime "%s │ │ %s" % (rCor, col.ENDC)
imprima "%s │ %s%s%s │ %s" % (rColour, " "*(20-(len(rText)/2)), rText, " "*(40-(20-(len(rText)/2))-len(rText)) , col.ENDC)
para i no intervalo (rPadding): imprime "%s │ │ %s" % (rCor, col.ENDC)
imprimir "%s └────────────────────────────────────── ────┘% é" % (rCor, col.ENDC)
imprimir " "
def prepare(rType="MAIN"):
rPackages globais
se rType <> "PRINCIPAL": rPackages = rPackages[:-1]
printc("Preparando a Instalação")
para rFile em ["/var/lib/dpkg/lock-frontend", "/var/cache/apt/archives/lock", "/var/lib/dpkg/lock"]:
tente: os.remove(rFile)
exceto: passar
os.system("apt-get update> /dev/null")
printc("Removendo libcurl4 se instalado")
os.system("apt-get remove --auto-remove libcurl4 -y > /dev/null")
para rPackage em rPackages:
printc("Instalando %s" % rPackage)
os.system("apt-get install %s -y > /dev/null" % rPackage)
printc("Instalando libpng")
os.system("wget -q -O /tmp/libpng12.deb https://xtreamui.net/ck/libpng12-0_1.2.54-1ubuntu1_amd64.deb")
os.system("dpkg -i /tmp/libpng12.deb > /dev/null")
os.system("apt-get install -y > /dev/null") # Limpe acima
tente: os.remove("/tmp/libpng12.deb")
exceto: passar
tentar:
subprocess.check_output("getent passwd xtreamcodes> /dev/null".split())
exceto:
# Criar usuário
printc("Criando xtreamcodes de usuário")
os.system("adduser --system --shell /bin/false --group --disabled-login xtreamcodes > /dev/null")
se não, os.path.exists("/home/xtreamcodes"): os.mkdir("/home/xtreamcodes")
retornar verdadeiro
def install(rType="MAIN"):
instalação global, rDownloadURL
printc("Baixando Software")
tente: rURL = rDownloadURL[rInstall[rType]]
exceto:
printc("URL de download inválido!", col.FAIL)
retorna falso
os.system('wget -q -O "/tmp/xtreamcodes.tar.gz" "%s"' % rURL)
se os.path.exists("/tmp/xtreamcodes.tar.gz"):
printc("Instalando Software")
os.system('tar -zxvf "/tmp/xtreamcodes.tar.gz" -C "/home/xtreamcodes/" > /dev/null')
tente: os.remove("/tmp/xtreamcodes.tar.gz")
exceto: passar
retornar verdadeiro
printc("Falha ao baixar o arquivo de instalação!", col.FAIL)
retorna falso
def mysql(rNome de usuário, rSenha):
rMySQLCnf global
printc("Configurando MySQL")
rCriar = Verdadeiro
se os.path.exists("/etc/mysql/my.cnf"):
if open("/etc/mysql/my.cnf", "r").read(14) == "# Códigos Xtream": rCreate = False
se rCreate:
shutil.copy("/etc/mysql/my.cnf", "/etc/mysql/my.cnf.xc")
rFile = open("/etc/mysql/my.cnf", "w")
rFile.write(rMySQLCnf)
rArquivo.close()
os.system("service mysql restart > /dev/null")
printc("Digite a senha raiz do MySQL:", col.WARNING)
para i no intervalo (5):
rMySQLRoot = raw_input(" ")
imprimir " "
if len(rMySQLRoot) > 0: rExtra = " -p%s" % rMySQLRoot
senão: rExtra = ""
printc("Descartar banco de dados existente e criar? S/N", col.WARNING)
if raw_input(" ").upper() == "Y": rDrop = True
senão: rDrop = Falso
tentar:
se rDrop:
os.system('mysql -u root%s -e "DROP DATABASE SE EXISTE xtream_iptvpro; CRIAR BANCO DE DADOS SE NÃO EXISTE xtream_iptvpro; > /dev/null' % rExtra)
os.system("mysql -u root%s xtream_iptvpro < /home/xtreamcodes/iptv_xtream_codes/database.sql > /dev/null" % rExtra)
os.system('mysql -u root%s -e "USE xtream_iptvpro; UPDATE configurações SET live_streaming_pass = \'%s\', unique_id = \'%s\& #39;, crypt_load_balancing = \'%s\';" > /dev/null' % (rExtra, gerar(20), gerar(10), gerar(20)))
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, latência , status, enable_geoip, geoip_countries, last_check_ago, can_delete, server_hardware, total_services, persistente_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) VA LUES (1, \ 39;Servidor Principal\', \'\', \'%s\', \'\', NULL, NULL, 0 , 25461, 1000, \'%s\', \'eth0\', 0, 1, 0, \'\', 0, 0 , \'{}\', 3, 0, 25462, \'baixa_prioridade\', \'\', \'baixa_prioridade\ ', 0, 1, \'\', 1000, 25463, \'\', \'[\"127.0.0.1\" ,\"\"]\', \'{}\', 0);" > /dev/null' % (rExtra, getIP(), getVersion ()))
os.system('mysql -u root%s -e "USE xtream_iptvpro; REPLACE INTO reg_users (id, nome de usuário, senha, email, member_group_id, verificado, status) VALORES (1, \'admin\ ', \'\$6\$rounds=20000\$xtreamcodes\$XThC5OwfuS0YwS4ahiifzF14vkGbGsFF1w7ETL4sRRC5sOrAWCjWvQJDromZUQoQuwbAXAFdX3h3Cp3vqulpS0\', \'admin@website.com\ ', 1, 1, 1 );" > /dev/null' % rExtra)
os.system('mysql -u root%s -e "CONCEDER TODOS OS PRIVILÉGIOS EM *.* PARA \'%s\'@\'%%\' ; IDENTIFICADO POR \'%s\' COM GRANT OPTION; FLUSH PRIVILEGES;" > /dev/null' % (rExtra, rUsername, rPassword))
tente: os.remove("/home/xtreamcodes/iptv_xtream_codes/database.sql")
exceto: passar
retornar verdadeiro
exceto: printc("Senha inválida! Tente novamente", col.FAIL)
retorna falso
def criptografar(rHost="127.0.0.1", rUsername="user_iptvpro", rPassword="", rDatabase="xtream_iptvpro", rServerID=1, rPort=7999):
printc("Criptografando...")
tente: os.remove("/home/xtreamcodes/iptv_xtream_codes/config")
exceto: passar
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), ciclo('5709650b0d7806074842c6de575025b1'))).encode('base64').replace('\n', ' 39;'))
rf.fechar()
def configurar():
printc("Configurando o Sistema")
se não "/home/xtreamcodes/iptv_xtream_codes/" em open("/etc/fstab").read():
rFile = open("/etc/fstab", "a")
rFile.write("tmpfs /home/xtreamcodes/iptv_xtream_codes/streams padrões tmpfs,noatime,nosuid,nodev,noexec,mode=1777,size=90% 0 0\ntmpfs /home/xtreamcodes/iptv_xtream_codes/tmp padrões tmpfs,noatime ,nosuid,nodev,noexec,mode=1777,tamanho=2G 0 0")
rArquivo.close()
se não "xtreamcodes" em open("/etc/sudoers").read():
os.system('echo "xtreamcodes ALL=(root) NOPASSWD: /sbin/iptables, /usr/bin/chattr" >> /etc/sudoers')
se não, os.path.exists("/etc/init.d/xtreamcodes"):
rStart = open("/etc/init.d/xtreamcodes", "w")
rStart.write("#!/bin/bash\n### BEGIN INIT INFO\n# Fornece: xtreamcodes\n# Início obrigatório: $all\n# Parada obrigatória:\n# Início padrão: 2 3 4 5\n# Default-Stop:\n# Breve descrição: Execute /etc/init.d/xtreamcodes se existir\n### END INIT INFO\nsleep 1\n/home/xtreamcodes/iptv_xtream_codes/start_services .sh > /dev/null")
rStart.close()
os.system("chmod +x /etc/init.d/xtreamcodes")
os.system("padrões de update-rc.d xtreamcodes")
os.system("update-rc.d xtreamcodes enable")
tente: os.remove("/usr/bin/ffmpeg")
exceto: passar
se não, 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("chown xtreamcodes:xtreamcodes -R /home/xtreamcodes> /dev/null")
os.system("chmod -R 0777 /home/xtreamcodes> /dev/null")
os.system("chmod +x /home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
os.system("chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb> /dev/null")
os.system("montar -a")
se não "api.xtream-codes.com" em open("/etc/hosts").read(): os.system('echo "127.0.0.1 api.xtream-codes.com" >> /etc/hosts')
se não "downloads.xtream-codes.com" em open("/etc/hosts").read(): os.system('echo "127.0.0.1 downloads.xtream-codes.com" >> /etc/hosts')
se não " xtream-codes.com" em open("/etc/hosts").read(): os.system('echo "127.0.0.1 xtream-codes.com" >> /etc/hosts')
os.system('apt-get install descompacte 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 && descompacte /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 {} +')
os.system("sed -i 's|echo \"Xtream Codes Reborn\";|header(\"Localização: https://www.google.com/\");| g' /home/xtreamcodes/iptv_xtream_codes/wwwdir/index.php")
os.system("sudo wget -q https://xtreamui.net/ck/youtube-dl -O /usr/local/bin/youtube-dl")
os.system("sudo chmod a+rx /usr/local/bin/youtube-dl")
def início(primeiro=Verdadeiro):
se primeiro: printc("Iniciando códigos Xtream")
else: printc("Reiniciando códigos Xtream")
os.system("/home/xtreamcodes/iptv_xtream_codes/start_services.sh 2>/dev/null")
os.system("chattr +i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb")
def modificarNginx():
printc("Modificando Nginx")
rPath = "/home/xtreamcodes/iptv_xtream_codes/nginx/conf/nginx.conf"
rPrevData = open(rPath, "r").read()
se não "ouça 25500" em rPrevData:
shutil.copy(rPath, "%s.xc"% rPath)
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 ativado;\n fastcgi_buffers 96 32k;\n fastcgi_buffer_size 32k;\n fastcgi_max_temp_file_size 0;\n fastcgi_keep_conn ativado;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi _param SCRIPT_NAME $ fastcgi_script_name;\n }\n }\n#CONFIGURAÇÃO DO ISP\n\n servidor {\n escutar 8805;\n root /home/xtreamcodes/iptv_xtream_codes/isp/;\n localização / {\n permitir 127.0.0.1;\ n negar tudo;\n }\n localização ~ \.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 ativado;\n fastcgi_buffers 96 32k;\n fastcgi_buffer_size 32k;\n fastcgi_max_temp_file_size 0;\n fastcgi_keep_conn ativado;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi_param SCRIPT_NAME $fastcgi_script_name;\n }\n }\ n}"
rArquivo = abrir(rPath, "w")
rArquivo.write(rData)
rArquivo.close()
se __nome__ == "__main__":
printc("CK41 MOD - Renascido por DRMStuff.com", col.OKGREEN, 2)
rType = raw_input(" Tipo de instalação [MAIN, LB]: ")
imprimir " "
se rType.upper() em ["MAIN", "LB"]:
se rType.upper() == "LB":
rHost = raw_input(" Endereço IP do servidor principal: ")
rPassword = raw_input(" Senha do MySQL: ")
tente: rServerID = int(raw_input(" ID do servidor do balanceador de carga: "))
exceto: rServerID = -1
imprimir " "
outro:
rHost = "127.0.0.1"
rSenha = gerar()
rServerID = 1
rUsername = "user_iptvpro"
rDatabase = "xtream_iptvpro"
rPort = 7999
if len(rHost) > 0 e len(rPassword) > 0 e rServerID> -1:
printc("Iniciar instalação? S/N", col.WARNING)
se raw_input(" ").upper() == "Y":
imprimir " "
rRet = prepare(rType.upper())
se não instalar(rType.upper()): sys.exit(1)
if rType.upper() == "PRINCIPAL":
se não for mysql (rUsername, rPassword): sys.exit (1)
criptografar (rHost, rUsername, rPassword, rDatabase, rServerID, rPort)
configurar()
if rType.upper() == "PRINCIPAL": modificarNginx()
começar()
printc("Xtream UI 22 CK41 MOD Reborn", col.OKGREEN, 2)
printc("IU do administrador: http://%s:25500" % getIP())
if rType.upper() == "PRINCIPAL":
printc("Por favor, armazene sua senha do MySQL!")
printc(rSenha)
senão: printc("Instalação cancelada", col.FAIL)
else: printc("Entradas inválidas", col.FAIL)
else: printc("Tipo de instalação inválido", col.FAIL)