-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to python3 => 3.8
- Loading branch information
Showing
1 changed file
with
56 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,84 @@ | ||
#! /usr/bin/env python2 | ||
#! /usr/bin/env python3 | ||
# | ||
# Configuration tool for tor_ip_switcher /etc/tor/torrc | ||
# | ||
# Usage: tips_setup.py <your_new_password> | ||
# | ||
# By Rupe 08.21.2018 | ||
# By Rupe 08.21.2018, updated 01.23.2022 | ||
|
||
from __future__ import print_function, unicode_literals | ||
|
||
from commands import getoutput | ||
from os import geteuid, devnull | ||
from os import devnull, geteuid | ||
from os.path import basename, isfile | ||
from subprocess import call | ||
from sys import argv, stdout, stderr | ||
from subprocess import call, getoutput | ||
from sys import argv, stderr, stdout | ||
from time import sleep | ||
|
||
ControlHashedPassword = ''.join( | ||
getoutput('tor --hash-password "%s"' % ''.join(argv[1:])).split()[-1:]) | ||
|
||
|
||
def controlPort_setup(): | ||
call(["sed", "-i", "/ControlPort /s/^#//", "/etc/tor/torrc"]) | ||
call(["sed", "-i", "/HashedControlPassword /s/^#//", "/etc/tor/torrc"]) | ||
call(["sed", "-i", "/ControlPort /s/^#//", "/etc/tor/torrc"]) | ||
call(["sed", "-i", "/HashedControlPassword /s/^#//", "/etc/tor/torrc"]) | ||
|
||
|
||
def controlHashed_password(): | ||
call( | ||
[ | ||
call([ | ||
"sed", | ||
"-i", | ||
"s/^HashedControlPassword 16:.*[A-Z0-9]/HashedControlPassword %s/" | ||
% ControlHashedPassword, | ||
"s/^HashedControlPassword 16:.*[A-Z0-9]/HashedControlPassword %s/" % | ||
ControlHashedPassword, | ||
"/etc/tor/torrc", | ||
] | ||
) | ||
]) | ||
|
||
|
||
def reload_tor_config(): | ||
tor_running = getoutput('pidof tor') | ||
if tor_running: | ||
call(['kill', '-HUP', '%s' % tor_running], stderr=open(devnull,'w')) | ||
print("\n \033[92m[" + u'\u2714' + "]\033[0m Tor Config: Reloaded") | ||
else: | ||
print("\n \033[91m[" + u'\u2718' + "]\033[0m Tor Daemon: Not running") | ||
if tor := getoutput('pidof tor'): | ||
call(['kill', '-HUP', '%s' % tor], stderr=open(devnull, 'w')) | ||
print("\n \033[92m[" + '\u2714' + "]\033[0m Tor Config: Reloaded") | ||
else: | ||
print("\n \033[91m[" + '\u2718' + "]\033[0m Tor Daemon: Not running") | ||
|
||
|
||
if __name__ == '__main__': | ||
if geteuid() is not 0: | ||
exit('Run as super user!') | ||
if argv[1:] == list(): | ||
exit(" \n[!] Usage: %s <your_new_password>\n" % basename(__file__)) | ||
else: | ||
try: | ||
info = \ | ||
""" | ||
if geteuid() != 0: | ||
exit('Run as super user!') | ||
if argv[1:] == list(): | ||
exit(" \n[!] Usage: %s <your_new_password>\n" % basename(__file__)) | ||
else: | ||
try: | ||
info = \ | ||
""" | ||
[\033[93m\u003F\033[0m] Gathering torrc config information [\033[93m\u003F\033[0m] | ||
""" | ||
if isfile('/etc/tor/torrc'): | ||
if 'HashedControlPassword' not in open('/etc/tor/torrc').read(): | ||
exit("\033[91m[!]\033[0m HashedControlPassword not in /etc/tor/torrc.") | ||
for i in info: | ||
sleep(.02) | ||
stdout.write(i) | ||
stdout.flush() | ||
controlPort_setup() | ||
controlHashed_password() | ||
reload_tor_config() | ||
print( | ||
" \033[92m[" + "\u2714" + "]\033[0m ControlPort 9051: Enabled\n", | ||
"\033[92m[" | ||
+ "\u2714" | ||
+ "]\033[0m HashedControlPassword: Enabled\n", | ||
"\033[92m[" | ||
+ "\u2714" | ||
+ "]\033[0m /etc/tor/torrc: Updated successfully\n", | ||
"\033[92m[" | ||
+ "\u2719" | ||
+ "]\033[0m Password set to: \033[92m" | ||
+ "%s" % "".join(argv[1:]) | ||
+ "\033[0m" | ||
+ "\n", | ||
"\033[92m[" | ||
+ "\u2719" | ||
+ "]\033[0m HashedControlPassword %s\n" % ControlHashedPassword | ||
) | ||
else: | ||
exit("\033[91m[!]\033[0m /etc/tor/torrc missing.") | ||
except Exception as err: | ||
print(err) | ||
if isfile('/etc/tor/torrc'): | ||
if 'HashedControlPassword' not in open('/etc/tor/torrc').read(): | ||
exit( | ||
"\033[91m[!]\033[0m HashedControlPassword not in /etc/tor/torrc." | ||
) | ||
for i in info: | ||
sleep(.02) | ||
stdout.write(i) | ||
stdout.flush() | ||
controlPort_setup() | ||
controlHashed_password() | ||
reload_tor_config() | ||
print( | ||
" \033[92m[" | ||
+ "\u2714" | ||
+ "]\033[0m ControlPort 9051: Enabled\n", "\033[92m[" | ||
+ "\u2714" | ||
+ "]\033[0m HashedControlPassword: Enabled\n", "\033[92m[" | ||
+ "\u2714" | ||
+ "]\033[0m /etc/tor/torrc: Updated successfully\n", "\033[92m[" | ||
+ "\u2719" | ||
+ "]\033[0m Password set to: \033[92m" | ||
+ "%s" % "".join(argv[1:]) | ||
+ "\033[0m" | ||
+ "\n", "\033[92m[" | ||
+ "\u2719" | ||
+ "]\033[0m HashedControlPassword %s\n" % ControlHashedPassword | ||
) | ||
else: | ||
exit("\033[91m[!]\033[0m /etc/tor/torrc missing.") | ||
except Exception as err: | ||
print(err) |