-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigupdate.py
More file actions
73 lines (52 loc) · 2.18 KB
/
Copy pathconfigupdate.py
File metadata and controls
73 lines (52 loc) · 2.18 KB
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
#!/usr/bin/env python3
import time, threading, logging
from os import remove, path
from hashlib import sha1
Logger = logging.getLogger(__name__)
class ConfigThread(threading.Thread):
def __init__(self, configfile):
super().__init__()
self.filename = configfile
self.options = ["password", "lightning", "rain", "dateformat", "gps", "gpsport", "gpsbaud", "url", "emailaccount", "emailpassword"]
self.file_hash = ""
self.config = None
self.update_config()
self._updated = False
with open(".config") as c:
lines = c.read().split("\n")
self.logfile = lines[2].split(' ')[1].strip()
self.dateformat = lines[3].split(' ')[1].strip()
def get_status(self):
return self._updated
def set_status(self,status):
self._updated = status
def update_config(self):
newconfig = {}
with open(self.filename) as c:
lines = c.read().split("\n")
for line in lines:
if len(line) > 2:
cdata = line.split(' ')
key = cdata[0].lower()
value = ' '.join(cdata[1:]) #allows for spaces in passwords and other values
if key in self.options:
newconfig[key] = value
else:
Logger.warning(f"[!] Invalid key {key} with value {value} provided in config file!")
self.config = newconfig
self.set_status(True)
self.update_file_hash()
def update_file_hash(self):
self.file_hash = self.get_hash(self.filename)
def get_hash(self,filename):
return sha1(filename.encode('utf-8')).hexdigest()
def run(self):
try:
while True:
if self.file_hash != self.get_hash(self.filename):
self.update_config()
time.sleep(30) #takes 30 seconds to update config file
except KeyboardInterrupt:
exit()
except Exception as e:
Logger.exception(e)