Use of WHOOGLE_TOR_CONF as env var

This commit is contained in:
MadcowOG 2022-05-04 00:54:40 -07:00
parent e1d6ed23f8
commit 7f56e16329
3 changed files with 18 additions and 12 deletions

View File

@ -343,6 +343,7 @@ There are a few optional environment variables available for customizing a Whoog
| WHOOGLE_MINIMAL | Remove everything except basic result cards from all search queries. | | WHOOGLE_MINIMAL | Remove everything except basic result cards from all search queries. |
| WHOOGLE_CSP | Sets a default set of 'Content-Security-Policy' headers | | WHOOGLE_CSP | Sets a default set of 'Content-Security-Policy' headers |
| WHOOGLE_RESULTS_PER_PAGE | Set the number of results per page | | WHOOGLE_RESULTS_PER_PAGE | Set the number of results per page |
| WHOOGLE_TOR_CONF | The absolute path to the config file containing the password for the tor control port. Default: {whoogle path}/misc/tor/control.conf |
### Config Environment Variables ### Config Environment Variables
These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time.

View File

@ -149,7 +149,12 @@ app.jinja_env.globals.update(
Session(app) Session(app)
# Attempt to acquire tor identity, to determine if Tor config is available # Attempt to acquire tor identity, to determine if Tor config is available
send_tor_signal(Signal.HEARTBEAT) try:
send_tor_signal(
Signal.HEARTBEAT,
confloc=os.getenv('WHOOGLE_TOR_CONF'))
except TypeError:
send_tor_signal(Signal.HEARTBEAT)
from app import routes # noqa from app import routes # noqa

View File

@ -37,14 +37,15 @@ class TorError(Exception):
super().__init__(message) super().__init__(message)
def send_tor_signal(signal: Signal) -> bool: def send_tor_signal(signal: Signal, confloc='./misc/tor/control.conf') -> bool:
try: with open(confloc, "r") as conf:
# Try to authenticate with password.
with Controller.from_port(port=9051) as c:
with open("./misc/tor/control.conf", "r") as conf:
for line in conf: for line in conf:
pass pass
secret = line secret = line
conf.close()
try:
# Try to authenticate with password.
with Controller.from_port(port=9051) as c:
authenticate_password(c, password=secret) authenticate_password(c, password=secret)
c.signal(signal) c.signal(signal)
os.environ['TOR_AVAILABLE'] = '1' os.environ['TOR_AVAILABLE'] = '1'
@ -66,8 +67,7 @@ def send_tor_signal(signal: Signal) -> bool:
os.environ['TOR_AVAILABLE'] = '0' os.environ['TOR_AVAILABLE'] = '0'
print( print(
"Unable to authenticate with tor control port." + "Unable to authenticate with tor control port." +
"Tor will be unavailable." " Tor will be unavailable.")
)
return False return False