Update torghostng.py

This commit is contained in:
Git Kern3l 2020-04-27 21:49:37 +07:00 committed by GitHub
parent dd581b550d
commit bdac1510de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,16 +10,15 @@ from os import geteuid, system, path, name
try:
from torngconf.theme import *
except ModuleNotFoundError:
print("TorghostNG is lacking its needed files. Reinstall TorghostNG pls")
print("TorghostNG is lacking its needed files. Reinstall TorghostNG from Github pls")
exit()
SLEEP_TIME = 1.0
VERSION = "1.2"
VERSION = "1.3"
def the_argparse(language=English):
parser = argparse.ArgumentParser(usage="torghostng [-h] -s|-x|-id|-r|-m|-c|-l|--list", add_help=False)
parser = argparse.ArgumentParser(usage="torghostng [-h] -s|-x|-id|-r|-m|-c|-l|--list")
parser._optionals.title = language.options
parser.add_argument("-h","--help", help=language.help_help, action="help", default=argparse.SUPPRESS)
parser.add_argument("-s","--start", help=language.start_help, action="store_true")
parser.add_argument("-x", "--stop", help=language.stop_help, action="store_true")
parser.add_argument("-r", "--renew", help=language.circuit_help, action="store_true")
@ -56,10 +55,10 @@ Sysctl = '/etc/sysctl.conf'
TOR_UID = getoutput('id -ur {}'.format(TOR_USER))
FIX_DNS = """nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844"""
FIX_DNS = """nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 2606:4700:4700::1111
nameserver 2606:4700:4700::1001"""
DISABLE_IPv6 = """net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1"""
@ -127,6 +126,61 @@ sudo python3 install.py && sudo python3 install.py"""
def banner():
print(the_banner)
print(language.description)
def check_lang():
try:
if path.isfile(LANGCONF) == True:
with open(LANGCONF) as file_lang:
language = eval(file_lang.readline())
file_lang.close()
print(language.applying_language, end='', flush=True)
print(language.done)
return language
else:
language = choose_lang()
return language
except KeyboardInterrupt:
print()
exit()
except (NameError, SyntaxError, AttributeError):
language = choose_lang()
return language
except FileNotFoundError:
print("TorghostNG is lacking its needed files. Reinstall TorghostNG from Github pls")
exit()
def choose_lang(language=English):
try:
with open(LANGCONF, mode="w") as file_lang:
print(language.language_list)
choice = int(input(language.choose_your_lang))
if choice == 1:
print(English.applying_language)
file_lang.write("English")
language = English
elif choice == 2:
print(Vietnamese.applying_language)
file_lang.write("Vietnamese")
language = Vietnamese
else:
print()
print(language.invalid_choice)
choose_lang()
file_lang.close()
return language
except KeyboardInterrupt:
print()
exit()
def check_windows_check_root():
if name == "nt":
@ -206,74 +260,13 @@ def check_ip():
print()
exit()
def check_lang():
try:
if path.isfile(LANGCONF) == True:
with open(LANGCONF) as file_lang:
lang = eval(file_lang.readline())
file_lang.close()
print(lang.applying_language, end='', flush=True)
sleep(SLEEP_TIME)
print(lang.done)
return lang
else:
lang = choose_lang()
return lang
except KeyboardInterrupt:
print()
exit()
except (NameError, SyntaxError):
lang = choose_lang()
return lang
except FileNotFoundError:
print("TorghostNG is lacking its needed files. Reinstall TorghostNG pls")
exit()
def choose_lang(language=English):
try:
with open(LANGCONF, mode="w") as file_lang:
file_lang.truncate(0)
print(language.language_list)
choice = int(input(language.choose_your_lang))
if choice == 1:
print(English.applying_language, end='', flush=True)
file_lang.write("English")
sleep(SLEEP_TIME)
print(English.done)
print(English.current_language + "English")
return English
if choice == 2:
print(Vietnamese.applying_language, end='', flush=True)
file_lang.write("Vietnamese")
sleep(SLEEP_TIME)
print(Vietnamese.done)
print(Vietnamese.current_language + "Vietnamese")
return Vietnamese
else:
print(language.invalid_choice)
choose_lang()
file_lang.close()
except KeyboardInterrupt:
print()
exit()
def start_connecting(id=None):
try:
print(icon.process + ' ' + language.start_help)
# Disable IPv6
if DISABLE_IPv6 == open(Sysctl).read():
print(language.ipv6_alreay_disabled)
getoutput('sudo sysctl -p')
else:
print(language.disable_ipv6_info)
@ -284,20 +277,20 @@ def start_connecting(id=None):
with open(Sysctl, mode='w') as file_sysctl:
file_sysctl.write(DISABLE_IPv6)
file_sysctl.close()
getoutput('sudo sysctl -p')
sleep(SLEEP_TIME)
print(language.done)
getoutput('sudo sysctl -p')
if id != None:
# Configure Torrc
if id != None: # Check for exit node
torrconfig = TorrcConfig_exitnode %(id)
print(language.id_tip)
else:
torrconfig = TorrcConfig
if (path.isfile(Torrc)) and (torrconfig == open(Torrc).read()):
print(language.already_configured.format('TorghostNG Torrc'))
@ -311,7 +304,7 @@ def start_connecting(id=None):
sleep(SLEEP_TIME)
print(language.done)
# Configure DNS resolv.conf
if resolvConfig == open(resolv).read():
print(language.already_configured.format('DNS resolv.conf'))
@ -321,11 +314,11 @@ def start_connecting(id=None):
with open(resolv, mode='w') as file_resolv:
print(language.configuring.format('DNS resolv.conf'), end='', flush=True)
file_resolv.write(resolvConfig)
file_resolv.close()
sleep(SLEEP_TIME)
print(language.done)
file_resolv.close()
# Stop and start new tor service
print(language.stopping_tor, end='', flush=True)
system('systemctl stop tor')
system('fuser -k 9051/tcp > /dev/null 2>&1')
@ -336,18 +329,20 @@ def start_connecting(id=None):
system('sudo -u {0} tor -f {1} > /dev/null'.format(TOR_USER, Torrc))
sleep(SLEEP_TIME)
print(language.done)
# Show some info
print(language.iptables_info)
print(language.block_bittorrent)
# Configure iptables
print(language.setting_iptables, end='', flush=True)
system(iptables_rules)
sleep(SLEEP_TIME)
print(language.done)
check_tor('failed')
print(language.dns_tip)
check_tor('failed') # Check tor connection
print(language.dns_tip) # Show some info
except KeyboardInterrupt:
print()
@ -357,6 +352,7 @@ def stop_connecting():
try:
print(icon.process + ' ' + language.stop_help)
# Restore DNS resolv.conf configuration
if path.isfile('/etc/resolv.conf.backup') == True:
print(language.restoring_configuration.format('DNS resolv.conf'), end='', flush=True)
@ -364,7 +360,8 @@ def stop_connecting():
sleep(SLEEP_TIME)
print(language.done)
# Restore IPv6 configuration
if path.isfile('/etc/sysctl.conf.backup') == True:
print(language.restoring_configuration.format('IPv6'), end='', flush=True)
@ -374,20 +371,22 @@ def stop_connecting():
sleep(SLEEP_TIME)
print(language.done)
# Reset iptables configuration
print(language.flushing_iptables, end='', flush=True)
system(IpFlush)
system('fuser -k 9051/tcp > /dev/null 2>&1')
sleep(SLEEP_TIME)
print(language.done)
# Restart NetworkManager
print(language.restarting_network, end='', flush=True)
system('systemctl restart --now NetworkManager')
sleep(8)
print(language.done)
check_tor('stopped')
check_tor('stopped') # Check tor connection
print(language.dns_tip)
print(language.dns_tip) # Show some info
except KeyboardInterrupt:
print()