-
Notifications
You must be signed in to change notification settings - Fork 49
/
tips_setup.py
81 lines (73 loc) · 2.47 KB
/
tips_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /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, updated 01.23.2022
from os import devnull, geteuid
from os.path import basename, isfile
from subprocess import call, getoutput
from sys import exit, 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"])
def controlHashed_password():
call([
"sed",
"-i",
"s/^HashedControlPassword 16:.*[A-Z0-9]/HashedControlPassword %s/" %
ControlHashedPassword,
"/etc/tor/torrc",
])
def reload_tor_config():
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() != 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)