aboutsummaryrefslogtreecommitdiff
path: root/security/howdy/files/patch-paths
blob: 57e375f2dea5939bdb9d4dd51404a5af6c885369 (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
From 30034c66d72e8e15e2ad5db68d1a5940df2568b6 Mon Sep 17 00:00:00 2001
From: Gleb Popov <6yearold@gmail.com>
Date: Thu, 30 Mar 2023 21:55:11 +0300
Subject: [PATCH] Put all path variables into a separate module.

This makes it easier for downstream packagers to customize where howdy installs
its files.
---
 howdy/src/cli/add.py     | 22 ++++++++++------------
 howdy/src/cli/clear.py   |  9 ++++-----
 howdy/src/cli/config.py  |  3 ++-
 howdy/src/cli/disable.py |  3 ++-
 howdy/src/cli/list.py    |  7 +++----
 howdy/src/cli/remove.py  |  9 ++++-----
 howdy/src/cli/set.py     |  3 ++-
 howdy/src/cli/snap.py    |  5 ++---
 howdy/src/cli/test.py    | 11 ++++++-----
 howdy/src/compare.py     | 18 ++++++++----------
 howdy/src/paths.py       | 12 ++++++++++++
 howdy/src/snapshot.py    | 15 ++++++---------
 12 files changed, 61 insertions(+), 56 deletions(-)
 create mode 100644 howdy/src/paths.py

diff --git a/howdy/src/cli/add.py b/howdy/src/cli/add.py
index 7a6d9eca..5a63bdfe 100644
--- a/howdy/src/cli/add.py
+++ ./howdy/src/cli/add.py
@@ -8,6 +8,7 @@
 import configparser
 import builtins
 import numpy as np
+import paths

 from recorders.video_capture import VideoCapture
 from i18n import _
@@ -26,39 +27,36 @@
 # OpenCV needs to be imported after dlib
 import cv2

-# Define the absolute path to the config directory
-config_path = "/etc/howdy"
-
 # Test if at lest 1 of the data files is there and abort if it's not
-if not os.path.isfile(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"):
+if not os.path.isfile(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat"):
 	print(_("Data files have not been downloaded, please run the following commands:"))
-	print("\n\tcd " + config_path + "/dlib-data")
+	print("\n\tcd " + paths.dlib_data_dir)
 	print("\tsudo ./install.sh\n")
 	sys.exit(1)

 # Read config from disk
 config = configparser.ConfigParser()
-config.read(config_path + "/config.ini")
+config.read(paths.config_dir + "/config.ini")

 use_cnn = config.getboolean("core", "use_cnn", fallback=False)
 if use_cnn:
-	face_detector = dlib.cnn_face_detection_model_v1(config_path + "/dlib-data/mmod_human_face_detector.dat")
+	face_detector = dlib.cnn_face_detection_model_v1(paths.dlib_data_dir + "mmod_human_face_detector.dat")
 else:
 	face_detector = dlib.get_frontal_face_detector()

-pose_predictor = dlib.shape_predictor(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat")
-face_encoder = dlib.face_recognition_model_v1(config_path + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
+pose_predictor = dlib.shape_predictor(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat")
+face_encoder = dlib.face_recognition_model_v1(paths.dlib_data_dir + "dlib_face_recognition_resnet_model_v1.dat")

 user = builtins.howdy_user
 # The permanent file to store the encoded model in
-enc_file = config_path + "/models/" + user + ".dat"
+enc_file = paths.user_models_dir + user + ".dat"
 # Known encodings
 encodings = []

 # Make the ./models folder if it doesn't already exist
-if not os.path.exists(config_path + "/models"):
+if not os.path.exists(paths.user_models_dir):
 	print(_("No face model folder found, creating one"))
-	os.makedirs(config_path + "/models")
+	os.makedirs(paths.user_models_dir)

 # To try read a premade encodings file if it exists
 try:
diff --git a/howdy/src/cli/clear.py b/howdy/src/cli/clear.py
index 6fa5f3ef..aa43e152 100644
--- a/howdy/src/cli/clear.py
+++ ./howdy/src/cli/clear.py
@@ -4,21 +4,20 @@
 import os
 import sys
 import builtins
+import paths

 from i18n import _

-# Get the full path to this file
-path = "/etc/howdy/models"
 # Get the passed user
 user = builtins.howdy_user

 # Check if the models folder is there
-if not os.path.exists(path):
+if not os.path.exists(paths.user_models_dir):
 	print(_("No models created yet, can't clear them if they don't exist"))
 	sys.exit(1)

 # Check if the user has a models file to delete
-if not os.path.isfile(path + "/" + user + ".dat"):
+if not os.path.isfile(paths.user_models_dir + user + ".dat"):
 	print(_("{} has no models or they have been cleared already").format(user))
 	sys.exit(1)

@@ -34,5 +33,5 @@
 		sys.exit(1)

 # Delete otherwise
-os.remove(path + "/" + user + ".dat")
+os.remove(paths.user_models_dir + user + ".dat")
 print(_("\nModels cleared"))
diff --git a/howdy/src/cli/config.py b/howdy/src/cli/config.py
index 71064839..04c51798 100644
--- a/howdy/src/cli/config.py
+++ ./howdy/src/cli/config.py
@@ -3,6 +3,7 @@
 # Import required modules
 import os
 import subprocess
+import paths

 from i18n import _

@@ -19,4 +20,4 @@
 	editor = "/etc/alternatives/editor"

 # Open the editor as a subprocess and fork it
-subprocess.call([editor, "/etc/howdy/config.ini"])
+subprocess.call([editor, paths.config_dir + "config.ini"])
diff --git a/howdy/src/cli/disable.py b/howdy/src/cli/disable.py
index be78c97f..1f655412 100644
--- a/howdy/src/cli/disable.py
+++ ./howdy/src/cli/disable.py
@@ -6,11 +6,12 @@
 import builtins
 import fileinput
 import configparser
+import paths

 from i18n import _

 # Get the absolute filepath
-config_path = os.path.dirname("/etc/howdy") + "/config.ini"
+config_path = os.path.dirname(paths.config_dir) + "/config.ini"

 # Read config from disk
 config = configparser.ConfigParser()
diff --git a/howdy/src/cli/list.py b/howdy/src/cli/list.py
index 3532e9f8..7539837d 100644
--- a/howdy/src/cli/list.py
+++ ./howdy/src/cli/list.py
@@ -6,21 +6,20 @@
 import json
 import time
 import builtins
+import paths

 from i18n import _

-# Get the absolute path and the username
-path = "/etc/howdy"
 user = builtins.howdy_user

 # Check if the models file has been created yet
-if not os.path.exists(path + "/models"):
+if not os.path.exists(paths.user_models_dir):
 	print(_("Face models have not been initialized yet, please run:"))
 	print("\n\tsudo howdy -U " + user + " add\n")
 	sys.exit(1)

 # Path to the models file
-enc_file = path + "/models/" + user + ".dat"
+enc_file = paths.user_models_dir + user + ".dat"

 # Try to load the models file and abort if the user does not have it yet
 try:
diff --git a/howdy/src/cli/remove.py b/howdy/src/cli/remove.py
index 6321e0b5..37894422 100644
--- a/howdy/src/cli/remove.py
+++ ./howdy/src/cli/remove.py
@@ -5,11 +5,10 @@
 import os
 import json
 import builtins
+import paths

 from i18n import _

-# Get the absolute path and the username
-path = "/etc/howdy"
 user = builtins.howdy_user

 # Check if enough arguments have been passed
@@ -22,13 +21,13 @@
 	sys.exit(1)

 # Check if the models file has been created yet
-if not os.path.exists(path + "/models"):
+if not os.path.exists(paths.user_models_dir):
 	print(_("Face models have not been initialized yet, please run:"))
 	print("\n\thowdy add\n")
 	sys.exit(1)

 # Path to the models file
-enc_file = path + "/models/" + user + ".dat"
+enc_file = paths.user_models_dir + user + ".dat"

 # Try to load the models file and abort if the user does not have it yet
 try:
@@ -72,7 +71,7 @@

 # Remove the entire file if this encoding is the only one
 if len(encodings) == 1:
-	os.remove(path + "/models/" + user + ".dat")
+	os.remove(paths.user_models_dir + user + ".dat")
 	print(_("Removed last model, howdy disabled for user"))
 else:
 	# A place holder to contain the encodings that will remain
diff --git a/howdy/src/cli/set.py b/howdy/src/cli/set.py
index 14d15c20..efbbee5b 100644
--- a/howdy/src/cli/set.py
+++ ./howdy/src/cli/set.py
@@ -5,11 +5,12 @@
 import os
 import builtins
 import fileinput
+import paths

 from i18n import _

 # Get the absolute filepath
-config_path = os.path.dirname("/etc/howdy") + "/config.ini"
+config_path = os.path.dirname(paths.config_dir) + "/config.ini"

 # Check if enough arguments have been passed
 if len(builtins.howdy_args.arguments) < 2:
diff --git a/howdy/src/cli/snap.py b/howdy/src/cli/snap.py
index cbcae501..2c625d3b 100644
--- a/howdy/src/cli/snap.py
+++ ./howdy/src/cli/snap.py
@@ -5,15 +5,14 @@
 import configparser
 import datetime
 import snapshot
+import paths
 from recorders.video_capture import VideoCapture

 from i18n import _

-path = "/etc/howdy"
-
 # Read the config
 config = configparser.ConfigParser()
-config.read(path + "/config.ini")
+config.read(paths.config_dir + "config.ini")

 # Start video capture
 video_capture = VideoCapture(config)
diff --git a/howdy/src/cli/test.py b/howdy/src/cli/test.py
index 3a6e4d19..563be19b 100644
--- a/howdy/src/cli/test.py
+++ ./howdy/src/cli/test.py
@@ -10,6 +10,7 @@
 import dlib
 import cv2
 import numpy as np
+import paths

 from i18n import _
 from recorders.video_capture import VideoCapture
@@ -19,7 +20,7 @@

 # Read config from disk
 config = configparser.ConfigParser()
-config.read(path + "/config.ini")
+config.read(paths.config_dir + "config.ini")

 if config.get("video", "recording_plugin", fallback="opencv") != "opencv":
 	print(_("Howdy has been configured to use a recorder which doesn't support the test command yet, aborting"))
@@ -59,20 +60,20 @@ def print_text(line_number, text):

 if use_cnn:
 	face_detector = dlib.cnn_face_detection_model_v1(
-		path + "/dlib-data/mmod_human_face_detector.dat"
+		paths.dlib_data_dir + "mmod_human_face_detector.dat"
 	)
 else:
 	face_detector = dlib.get_frontal_face_detector()

-pose_predictor = dlib.shape_predictor(path + "/dlib-data/shape_predictor_5_face_landmarks.dat")
-face_encoder = dlib.face_recognition_model_v1(path + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
+pose_predictor = dlib.shape_predictor(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat")
+face_encoder = dlib.face_recognition_model_v1(paths.dlib_data_dir + "dlib_face_recognition_resnet_model_v1.dat")

 encodings = []
 models = None

 try:
 	user = builtins.howdy_user
-	models = json.load(open(path + "/models/" + user + ".dat"))
+	models = json.load(open(paths.user_models_dir + user + ".dat"))

 	for model in models:
 		encodings += model["data"]
diff --git a/howdy/src/compare.py b/howdy/src/compare.py
index 99f5285b..f81fe386 100644
--- a/howdy/src/compare.py
+++ ./howdy/src/compare.py
@@ -23,6 +23,7 @@
 import snapshot
 import numpy as np
 import _thread as thread
+import paths

 # Allow imports from the local howdy folder
 sys.path.append('/lib/security/howdy')
@@ -48,22 +49,22 @@ def init_detector(lock):
 	global face_detector, pose_predictor, face_encoder

 	# Test if at lest 1 of the data files is there and abort if it's not
-	if not os.path.isfile(PATH + "/dlib-data/shape_predictor_5_face_landmarks.dat"):
+	if not os.path.isfile(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat"):
 		print(_("Data files have not been downloaded, please run the following commands:"))
-		print("\n\tcd " + PATH + "/dlib-data")
+		print("\n\tcd " + paths.dlib_data_dir)
 		print("\tsudo ./install.sh\n")
 		lock.release()
 		exit(1)

 	# Use the CNN detector if enabled
 	if use_cnn:
-		face_detector = dlib.cnn_face_detection_model_v1(PATH + "/dlib-data/mmod_human_face_detector.dat")
+		face_detector = dlib.cnn_face_detection_model_v1(paths.dlib_data_dir + "mmod_human_face_detector.dat")
 	else:
 		face_detector = dlib.get_frontal_face_detector()

 	# Start the others regardless
-	pose_predictor = dlib.shape_predictor(PATH + "/dlib-data/shape_predictor_5_face_landmarks.dat")
-	face_encoder = dlib.face_recognition_model_v1(PATH + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
+	pose_predictor = dlib.shape_predictor(paths.dlib_data_dir + "shape_predictor_5_face_landmarks.dat")
+	face_encoder = dlib.face_recognition_model_v1(paths.dlib_data_dir + "dlib_face_recognition_resnet_model_v1.dat")

 	# Note the time it took to initialize detectors
 	timings["ll"] = time.time() - timings["ll"]
@@ -103,9 +104,6 @@ def send_to_ui(type, message):
 if len(sys.argv) < 2:
 	exit(12)

-# Get the absolute path to the config directory
-PATH = "/etc/howdy"
-
 # The username of the user being authenticated
 user = sys.argv[1]
 # The model file contents
@@ -129,7 +127,7 @@ def send_to_ui(type, message):

 # Try to load the face model from the models folder
 try:
-	models = json.load(open(PATH + "/models/" + user + ".dat"))
+	models = json.load(open(paths.user_models_dir + user + ".dat"))

 	for model in models:
 		encodings += model["data"]
@@ -142,7 +140,7 @@ def send_to_ui(type, message):

 # Read config from disk
 config = configparser.ConfigParser()
-config.read(PATH + "/config.ini")
+config.read(paths.config_dir + "config.ini")

 # Get all config values needed
 use_cnn = config.getboolean("core", "use_cnn", fallback=False)
diff --git a/howdy/src/paths.py b/howdy/src/paths.py
new file mode 100644
index 00000000..22825405
--- /dev/null
+++ ./howdy/src/paths.py
@@ -0,0 +1,12 @@
+
+# Define the absolute path to the config directory
+config_dir = "/etc/howdy/"
+
+# Define the absolute path to the DLib models data directory
+dlib_data_dir = config_dir + "/dlib-data/"
+
+# Define the absolute path to the Howdy user models directory
+user_models_dir = config_dir + "/models/"
+
+# Define path to any howdy logs
+log_path = "/var/log/howdy"
diff --git a/howdy/src/snapshot.py b/howdy/src/snapshot.py
index 324b5789..9f2f563c 100644
--- a/howdy/src/snapshot.py
+++ ./howdy/src/snapshot.py
@@ -49,19 +49,16 @@ def generate(frames, text_lines):

 		line_number += 1

-	# Define path to any howdy logs
-	log_path = "/var/log/howdy"
-
 	# Made sure a snapshot folder exist
-	if not os.path.exists(log_path):
-		os.makedirs(log_path)
-	if not os.path.exists(log_path + "/snapshots"):
-		os.makedirs(log_path + "/snapshots")
+	if not os.path.exists(paths.log_path):
+		os.makedirs(paths.log_path)
+	if not os.path.exists(paths.log_path + "/snapshots"):
+		os.makedirs(paths.log_path + "/snapshots")

 	# Generate a filename based on the current time
 	filename = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%S.jpg")
 	# Write the image to that file
-	cv2.imwrite(log_path + "/snapshots/" + filename, snap)
+	cv2.imwrite(paths.log_path + "/snapshots/" + filename, snap)

 	# Return the saved file location
-	return log_path + "/snapshots/" + filename
+	return paths.log_path + "/snapshots/" + filename