-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutils.py
executable file
·69 lines (56 loc) · 1.84 KB
/
utils.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
'''
Pi-hole DNS traffic visualizer for the Raspberry Pi Sense HAT
By Sam Lindley, 2/21/2018
'''
import os
import re
import config
def color_dict(level):
return {
0 : (0, 0, 255),
1 : (0, 128, 255),
2 : (0, 255, 255),
3 : (255, 128, 0),
4 : (0, 255, 0),
5 : (128, 255, 0),
6 : (255, 255, 0),
7 : (255, 128, 0),
8 : (255, 0, 0),
}[level]
def parse_config(config_path):
pw_hash = ''
with open(config_path, 'r') as fp:
try:
for line in fp:
hex_pattern = re.compile(r'WEBPASSWORD=([0-9a-fA-F]+)')
match = re.match(hex_pattern, line)
if match:
pw_hash = match.group(1)
return pw_hash
except Exception:
return pw_hash
def retrieve_hash(address):
pw_hash = ''
if address == '127.0.0.1':
config_path = '/etc/pihole/setupVars.conf'
if os.getegid() != 0:
return pw_hash
else:
if os.path.exists(config_path):
return parse_config(config_path)
else:
if os.geteuid() == 0:
config.LOGGER.error("Pi-hole configuration file not found in default location '%s'." \
% config_path)
print("Pi-hole configuration file not found in default location '%s'." \
% config_path)
return pw_hash
else:
env_pw = os.environ.get("WEBPASSWORD", None)
if env_pw is None:
if os.geteuid() == 0:
config.LOGGER.warning("Environment variable containing password hash could not be found.")
print("Environment variable containing password hash could not be found.")
else:
pw_hash = env_pw
return pw_hash