2018-10-30 05:25:28 +08:00
#Checks functions
2018-10-28 10:42:24 +08:00
from urllib . request import urlopen
2018-12-06 09:06:41 +08:00
from os import *
2019-11-16 16:51:49 +08:00
from time import sleep
2018-10-28 10:42:24 +08:00
from subprocess import check_output
from platform import system as systemos , architecture
from wget import download
2018-11-20 01:49:09 +08:00
from Defs . Languages import *
2018-12-06 09:06:41 +08:00
import os
2019-11-16 16:51:49 +08:00
import subprocess
2018-12-06 09:06:41 +08:00
import ctypes
2018-10-28 10:42:24 +08:00
RED , GREEN , DEFAULT = ' \033 [91m ' , ' \033 [1;32m ' , ' \033 [0m '
2018-11-30 07:20:52 +08:00
installGetText ( )
2018-11-29 04:56:33 +08:00
languageSelector ( )
2019-06-30 19:05:41 +08:00
2019-01-01 09:28:13 +08:00
def checkConnection ( host = ' https://google.com ' ) : #Connection check
2019-04-21 18:15:55 +08:00
system ( ' clear ' )
2018-10-28 10:42:24 +08:00
try :
2019-07-13 22:57:58 +08:00
urlopen ( host , timeout = 10 )
2019-04-21 18:15:55 +08:00
print ( _ ( " {0} HURRAY!! Internet is available.. We can Continue {1} " ) . format ( GREEN , DEFAULT ) )
2019-11-16 16:51:49 +08:00
print ( _ ( " \n \n {0} Wait! Checking for Neccesary Packages {1} ... \n " ) . format ( GREEN , DEFAULT ) )
2018-10-28 10:42:24 +08:00
return True
except :
return False
2018-10-30 22:05:25 +08:00
2018-10-30 19:31:22 +08:00
if checkConnection ( ) == False :
2018-10-31 10:28:03 +08:00
print ( _ ( ''' {1}
2018-10-30 05:25:28 +08:00
_ _ . ___ ___ ___ _ _ { 0 } ___ _ _ ___ { 1 }
| __ | | ] | ] | | __ | \ | { 0 } | __ \__ / | __ { 1 }
| | | ] __ | ] __ | | __ | \| { 0 } | __ | | | __ { 1 }
2019-04-21 18:15:55 +08:00
{ 0 } [ { 1 } ! { 0 } ] { 1 } ^ Network error ^ . Verify your Internet connection . \n
2018-10-31 10:28:03 +08:00
''' ).format(RED, DEFAULT))
2018-10-30 22:23:28 +08:00
exit ( 0 )
2019-03-07 10:43:26 +08:00
2018-10-28 10:42:24 +08:00
def checkNgrok ( ) : #Ngrok check
if path . isfile ( ' Server/ngrok ' ) == False : #Is Ngrok downloaded?
2019-03-07 10:43:26 +08:00
print ( _ ( ' [*] Ngrok Not Found !! ' ) )
2018-10-31 10:28:03 +08:00
print ( _ ( ' [*] Downloading Ngrok... ' ) )
2019-05-03 09:05:12 +08:00
if ' Android ' in str ( check_output ( ( ' uname ' , ' -a ' ) ) ) or ' arm ' in str ( check_output ( ( ' uname ' , ' -a ' ) ) ) :
2018-10-28 10:42:24 +08:00
filename = ' ngrok-stable-linux-arm.zip '
else :
ostype = systemos ( ) . lower ( )
if architecture ( ) [ 0 ] == ' 64bit ' :
filename = ' ngrok-stable- {0} -amd64.zip ' . format ( ostype )
else :
filename = ' ngrok-stable- {0} -386.zip ' . format ( ostype )
url = ' https://bin.equinox.io/c/4VmDzA7iaHb/ ' + filename
download ( url )
system ( ' unzip ' + filename )
system ( ' mv ngrok Server/ngrok ' )
system ( ' rm -Rf ' + filename )
system ( ' clear ' )
2018-12-06 09:06:41 +08:00
2019-10-27 16:51:30 +08:00
def checkLocalxpose ( ) : #Localxpose check
if path . isfile ( ' Server/loclx ' ) == False : #Is Localxpose downloaded?
print ( _ ( ' [*] Localxpose Not Found !! ' ) )
print ( _ ( ' [*] Downloading Localxpose... ' ) )
if ' Android ' in str ( check_output ( ( ' uname ' , ' -a ' ) ) ) or ' arm ' in str ( check_output ( ( ' uname ' , ' -a ' ) ) ) :
filename = ' loclx-linux-arm.zip '
else :
ostype = systemos ( ) . lower ( )
if architecture ( ) [ 0 ] == ' 64bit ' :
filename = ' loclx-linux-amd64.zip ' . format ( ostype )
else :
filename = ' loclx-linux-386.zip ' . format ( ostype )
url = ' https://lxpdownloads.sgp1.digitaloceanspaces.com/cli/ ' + filename
download ( url )
system ( ' unzip loclx*.zip && rm loclx*.zip ' )
system ( ' mv loclx* loclx ' )
system ( ' mv loclx Server/ ' )
system ( ' clear ' )
2019-11-16 16:51:49 +08:00
def checkbinaryLT ( ) : #LocalTunnel Binary File check.
if path . isfile ( ' Server/lt ' ) == False : #Is LocalTunnel downloaded?
print ( _ ( ' [*] LocalTunnel Binary File Not Found !! ' ) )
print ( _ ( ' [*] Downloading LocalTunnel... ' ) )
system ( " apt install wget && pkg install wget && wget https://www.wa4e.com/downloads/lt-linux.zip " )
system ( ' unzip lt*.zip && rm lt*.zip && mv lt* lt && mv lt Server/lt ' )
system ( ' clear ' )
def checkLT ( ) : #Ask to install npm,node.js,localtunnel(packages).
if 256 == system ( ' which lt > /dev/null ' ) :
system ( ' clear ' )
print ( _ ( " {0} [ {1} ? {0} ] Do You Want To Install LOCALTUNNEL(Tunneling Service) Packages. \n {0} [ {1} * {0} ] {1} May take time , Skip if not wants to use LocalTunnel(Package Version). " ) . format ( RED , GREEN , DEFAULT ) )
choice = input ( " \n ( {1} Y {2} / {2} (N)>> {2} " . format ( RED , GREEN , DEFAULT ) )
if choice == ' y ' or choice == ' Y ' :
system ( ' clear ' )
installLT ( )
elif choice == ' n ' or choice == ' N ' :
print ( _ ( " \n {0} [ {1} ! {0} ] {0} You can not use LocalTunnel(Package Version). \n {0} [ {1} ! {0} ] {0} But still You Can Use LocalTunnel(Binary Version). \n \n \n " ) . format ( RED , GREEN , DEFAULT ) )
input ( ' Press Enter To Continue ' )
system ( ' clear ' )
else :
return checkLT ( )
else :
print ( " [*] LocalTunnel Packages Found !! " )
sleep ( 2 )
system ( ' clear ' )
def installLT ( ) : #Localtunnel check
print ( _ ( ' [*] Installing LocalTunnel... ' ) )
if ' Android ' in str ( check_output ( ( ' uname ' , ' -a ' ) ) ) or ' arm ' in str ( check_output ( ( ' uname ' , ' -a ' ) ) ) :
system ( " apt-get -y update;apt -y install nodejs npm;npm cache clean -f;npm i -g n;n stable;npm i -g localtunnel-termux;clear " )
checkagainLT ( )
else :
system ( " apt-get -y update;apt -y install nodejs npm;npm cache clean -f;npm i -g n;n stable;npm i -g localtunnel;clear " )
checkagainLT ( )
def checkagainLT ( ) : #Check if Localtunnel installed correctly or not.
if 256 == system ( ' which lt > /dev/null ' ) :
system ( ' clear ' )
print ( ' [ERROR]: LocalTunnel Packages Does Not Installed Correctly... ' )
print ( ' ' )
input ( ' [^] Press Enter To Go Back To installation.. ' )
checkLT ( )
else :
print ( ' [SUCCESS] LocalTunnel Installed. ' )
sleep ( 2 )
2019-10-27 16:51:30 +08:00
2018-12-06 09:06:41 +08:00
def checkPermissions ( ) :
if systemos ( ) == ' Linux ' :
if os . getuid ( ) == 0 :
print ( " {0} Permissions granted! " . format ( GREEN ) )
else :
2019-01-12 20:14:21 +08:00
raise PermissionError ( " {0} Permissions denied! Please run as ' {1} sudo {0} ' " . format ( RED , GREEN ) )
2018-12-06 09:06:41 +08:00
elif systemos ( ) == ' Windows ' :
if ctypes . windll . shell32 . IsUserAnAdmin ( ) != 0 :
print ( " {0} Permissions granted! " . format ( GREEN ) )
else :
2019-01-12 20:14:21 +08:00
raise PermissionError ( " {0} Permissions denied! Please run as Administrator " . format ( RED ) )
2019-07-30 19:24:16 +08:00
elif systemos ( ) == ' Darwin ' :
if os . getuid ( ) == 0 :
print ( " {0} Permissions granted! " . format ( GREEN ) )
else :
raise PermissionError ( " {0} Permissions denied! Please run as ' {1} sudo {0} ' " . format ( RED , GREEN ) )
2018-12-06 09:06:41 +08:00
else :
raise PermissionError ( " {0} Permissions denied! Unexpected platform " . format ( RED ) )