Skip to content

Commit

Permalink
towards fixing parsing torrc.d twice bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Schleizer committed Mar 5, 2020
1 parent e8266a8 commit 2e19758
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import fileinput, os, shutil

'''repair_torrc() function will be called when we want to guarantee the existence of:
1. /etc/torrc.d/95_whonix.conf
2. /etc/tor/torrc
3. "%include /etc/torrc.d/95_whonix.conf" line in /etc/tor/torrc file
1. "%include /etc/torrc.d/95_whonix.conf" line in /etc/tor/torrc file
2. "%include /usr/local/etc/torrc.d/" line in /etc/torrc.d/95_whonix.conf file
'''

if os.path.exists('/usr/share/anon-gw-base-files/gateway'):
Expand All @@ -21,14 +20,12 @@ def repair_torrc():

if not os.path.exists('/etc/torrc.d/95_whonix.conf'):
with open('/etc/torrc.d/95_whonix.conf', "w+") as f:
f.write("%include /usr/local/etc/torrc.d/40_tor_control_panel.conf")
f.write('\n')
f.write("%include /usr/local/etc/torrc.d/50_user.conf")
f.write("%include /usr/local/etc/torrc.d/")
f.write('\n')

if not os.path.exists('/etc/tor/torrc'):
with open('/etc/tor/torrc', "w+") as f:
f.write("%include /etc/torrc.d/95_whonix.conf")
f.write("%include /etc/torrc.d/")
f.write('\n')
else:
with open('/etc/tor/torrc', "r") as f:
Expand All @@ -38,12 +35,12 @@ def repair_torrc():
torrcd_line_exists = False
for line in lines:
str = line.strip()
if (str == '%include /etc/torrc.d/95_whonix.conf'):
if (str == '%include /etc/torrc.d/'):
torrcd_line_exists = True

if not torrcd_line_exists:
with open('/etc/tor/torrc', "a") as f:
f.write("%include /etc/torrc.d/95_whonix.conf\n")
f.write("%include /etc/torrc.d/")
f.write('\n')


Expand Down

0 comments on commit 2e19758

Please sign in to comment.