From 61512174660bf0769c994f0b8772da384f5bf9ec Mon Sep 17 00:00:00 2001 From: Patrizio Bruno Date: Tue, 5 Apr 2022 18:54:30 +0100 Subject: [PATCH 1/5] move config.ini and /models to /etc/howdy for better compatibility with immutable OSs --- howdy-gtk/src/tab_video.py | 2 +- howdy-gtk/src/window.py | 4 ++-- howdy/archlinux/howdy/.SRCINFO | 2 +- howdy/archlinux/howdy/PKGBUILD | 4 +++- howdy/debian/postinst | 6 +++--- howdy/debian/preinst | 8 +++++++- howdy/src/autocomplete/howdy | 2 +- howdy/src/cli/add.py | 10 ++++++---- howdy/src/cli/clear.py | 8 ++++---- howdy/src/cli/config.py | 3 ++- howdy/src/cli/disable.py | 2 +- howdy/src/cli/list.py | 2 +- howdy/src/cli/remove.py | 2 +- howdy/src/cli/set.py | 2 +- howdy/src/cli/snap.py | 5 ++--- howdy/src/cli/test.py | 2 +- howdy/src/compare.py | 4 ++-- howdy/src/pam.py | 2 +- howdy/src/pam/main.cc | 2 +- 19 files changed, 41 insertions(+), 31 deletions(-) diff --git a/howdy-gtk/src/tab_video.py b/howdy-gtk/src/tab_video.py index cd67740..d694fba 100644 --- a/howdy-gtk/src/tab_video.py +++ b/howdy-gtk/src/tab_video.py @@ -17,7 +17,7 @@ def on_page_switch(self, notebook, page, page_num): try: self.config = configparser.ConfigParser() - self.config.read("/lib/security/howdy/config.ini") + self.config.read("/etc/howdy/config.ini") except Exception: print(_("Can't open camera")) diff --git a/howdy-gtk/src/window.py b/howdy-gtk/src/window.py index 1bd58ff..125f44e 100644 --- a/howdy-gtk/src/window.py +++ b/howdy-gtk/src/window.py @@ -49,7 +49,7 @@ class MainWindow(gtk.Window): # Add the treeview self.modellistbox.add(self.treeview) - filelist = os.listdir("/lib/security/howdy/models") + filelist = os.listdir("/etc/howdy/models") self.active_user = "" self.userlist.items = 0 @@ -117,7 +117,7 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) elevate.elevate() # If no models have been created yet or when it is forced, start the onboarding -if "--force-onboarding" in sys.argv or not os.path.exists("/lib/security/howdy/models"): +if "--force-onboarding" in sys.argv or not os.path.exists("/etc/howdy/models"): import onboarding onboarding.OnboardingWindow() diff --git a/howdy/archlinux/howdy/.SRCINFO b/howdy/archlinux/howdy/.SRCINFO index cf7022d..28479d0 100644 --- a/howdy/archlinux/howdy/.SRCINFO +++ b/howdy/archlinux/howdy/.SRCINFO @@ -13,7 +13,7 @@ pkgbase = howdy depends = python3 depends = python-dlib depends = python-numpy - backup = usr/lib/security/howdy/config.ini + backup = etc/howdy/config.ini source = howdy-2.6.1.tar.gz::https://github.com/boltgolt/howdy/archive/v2.6.1.tar.gz source = https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2 source = https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2 diff --git a/howdy/archlinux/howdy/PKGBUILD b/howdy/archlinux/howdy/PKGBUILD index 1740ccb..4c5d32a 100644 --- a/howdy/archlinux/howdy/PKGBUILD +++ b/howdy/archlinux/howdy/PKGBUILD @@ -22,7 +22,7 @@ makedepends=( 'cmake' 'pkgfile' ) -backup=('usr/lib/security/howdy/config.ini') +backup=('etc/howdy/config.ini') source=( "$pkgname-$pkgver.tar.gz::https://github.com/boltgolt/howdy/archive/v${pkgver}.tar.gz" "https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2" @@ -39,7 +39,9 @@ package() { cd howdy-$pkgver install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" mkdir -p "$pkgdir/usr/lib/security/howdy" + mkdir -p "$pkgdir/etc/howdy" cp -r src/* "$pkgdir/usr/lib/security/howdy" + cp -r src/config.ini "$pkgdir/etc/howdy" cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp "${srcdir}/mmod_human_face_detector.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" diff --git a/howdy/debian/postinst b/howdy/debian/postinst index 0a31c74..1cf7ab0 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -52,7 +52,7 @@ if not os.path.exists("/tmp/howdy_picked_device"): oldConf = configparser.ConfigParser() oldConf.read("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") newConf = configparser.ConfigParser() - newConf.read("/lib/security/howdy/config.ini") + newConf.read("/etc/howdy/config.ini") # Go through every setting in the old config and apply it to the new file for section in oldConf.sections(): @@ -98,7 +98,7 @@ if not os.path.exists("/tmp/howdy_picked_device"): newConf.set(section, key, value) # Write it all to file - with open("/lib/security/howdy/config.ini", "w") as configfile: + with open("/etc/howdy/config.ini", "w") as configfile: newConf.write(configfile) # Install dlib data files if needed @@ -200,7 +200,7 @@ handleStatus(subprocess.call(["pip3", "install", "--no-cache-dir", "opencv-pytho log("Configuring howdy") # Manually change the camera id to the one picked -for line in fileinput.input(["/lib/security/howdy/config.ini"], inplace=1): +for line in fileinput.input(["/etc/howdy/config.ini"], inplace=1): line = line.replace("use_cnn = false", "use_cnn = " + str(cuda_used).lower()) print(line, end="") diff --git a/howdy/debian/preinst b/howdy/debian/preinst index 329438c..a01628b 100755 --- a/howdy/debian/preinst +++ b/howdy/debian/preinst @@ -14,7 +14,13 @@ if "upgrade" in sys.argv: # Let the user know so he knows where to look on a failed install print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") except subprocess.CalledProcessError: - print("Could not make an backup of old Howdy config file") + try: + subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + + # Let the user know so he knows where to look on a failed install + print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") + except subprocess.CalledProcessError: + print("Could not make an backup of old Howdy config file") # Don't continue setup when we're just upgrading sys.exit(0) diff --git a/howdy/src/autocomplete/howdy b/howdy/src/autocomplete/howdy index d633f22..fcfceb8 100755 --- a/howdy/src/autocomplete/howdy +++ b/howdy/src/autocomplete/howdy @@ -20,7 +20,7 @@ _howdy() { ;; # For disable, grab the current "disabled" config option and give the reverse "disable") - local status=$(cut -d'=' -f2 <<< $(cat /lib/security/howdy/config.ini | grep 'disabled =') | xargs echo -n) + local status=$(cut -d'=' -f2 <<< $(cat /etc/howdy/config.ini | grep 'disabled =') | xargs echo -n) [ "$status" == "false" ] && COMPREPLY="true" || COMPREPLY="false" return 0 diff --git a/howdy/src/cli/add.py b/howdy/src/cli/add.py index 1cab2e9..3dcd9ff 100644 --- a/howdy/src/cli/add.py +++ b/howdy/src/cli/add.py @@ -28,6 +28,8 @@ import cv2 # Get the absolute path to the current directory path = os.path.abspath(__file__ + "/..") +config_path = "/etc/howdy" +models_path = "/etc/howdy/models" # 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"): @@ -38,7 +40,7 @@ if not os.path.isfile(path + "/../dlib-data/shape_predictor_5_face_landmarks.dat # Read config from disk config = configparser.ConfigParser() -config.read(path + "/../config.ini") +config.read(config_path + "/config.ini") use_cnn = config.getboolean("core", "use_cnn", fallback=False) if use_cnn: @@ -51,14 +53,14 @@ face_encoder = dlib.face_recognition_model_v1(path + "/../dlib-data/dlib_face_re user = builtins.howdy_user # The permanent file to store the encoded model in -enc_file = path + "/../models/" + user + ".dat" +enc_file = models_path + "/" + user + ".dat" # Known encodings encodings = [] # Make the ./models folder if it doesn't already exist -if not os.path.exists(path + "/../models"): +if not os.path.exists(models_path): print(_("No face model folder found, creating one")) - os.makedirs(path + "/../models") + os.makedirs(models_path) # 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 22b6579..686e84a 100644 --- a/howdy/src/cli/clear.py +++ b/howdy/src/cli/clear.py @@ -8,17 +8,17 @@ import builtins from i18n import _ # Get the full path to this file -path = os.path.dirname(os.path.abspath(__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 + "/../models"): +if not os.path.exists(path): 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 + "/../models/" + user + ".dat"): +if not os.path.isfile(path + "/" + user + ".dat"): print(_("{} has no models or they have been cleared already").format(user)) sys.exit(1) @@ -34,5 +34,5 @@ if not builtins.howdy_args.y: sys.exit(1) # Delete otherwise -os.remove(path + "/../models/" + user + ".dat") +os.remove(path + "/" + user + ".dat") print(_("\nModels cleared")) diff --git a/howdy/src/cli/config.py b/howdy/src/cli/config.py index e2b0b0f..1582e8c 100644 --- a/howdy/src/cli/config.py +++ b/howdy/src/cli/config.py @@ -18,5 +18,6 @@ if "EDITOR" in os.environ: elif os.path.isfile("/etc/alternatives/editor"): editor = "/etc/alternatives/editor" +config_path = "/etc/howdy" # Open the editor as a subprocess and fork it -subprocess.call([editor, os.path.dirname(os.path.realpath(__file__)) + "/../config.ini"]) +subprocess.call([editor, os.path.dirname(config_path) + "/config.ini"]) diff --git a/howdy/src/cli/disable.py b/howdy/src/cli/disable.py index 485fe1a..1600d52 100644 --- a/howdy/src/cli/disable.py +++ b/howdy/src/cli/disable.py @@ -10,7 +10,7 @@ import configparser from i18n import _ # Get the absolute filepath -config_path = os.path.dirname(os.path.abspath(__file__)) + "/../config.ini" +config_path = os.path.dirname("/etc/howdy") + "/config.ini" # Read config from disk config = configparser.ConfigParser() diff --git a/howdy/src/cli/list.py b/howdy/src/cli/list.py index a098498..ab26c4d 100644 --- a/howdy/src/cli/list.py +++ b/howdy/src/cli/list.py @@ -10,7 +10,7 @@ import builtins from i18n import _ # Get the absolute path and the username -path = os.path.dirname(os.path.realpath(__file__)) + "/.." +path = "/etc/howdy" user = builtins.howdy_user # Check if the models file has been created yet diff --git a/howdy/src/cli/remove.py b/howdy/src/cli/remove.py index f9c29a4..6321e0b 100644 --- a/howdy/src/cli/remove.py +++ b/howdy/src/cli/remove.py @@ -9,7 +9,7 @@ import builtins from i18n import _ # Get the absolute path and the username -path = os.path.dirname(os.path.realpath(__file__)) + "/.." +path = "/etc/howdy" user = builtins.howdy_user # Check if enough arguments have been passed diff --git a/howdy/src/cli/set.py b/howdy/src/cli/set.py index 72c5c8e..14d15c2 100644 --- a/howdy/src/cli/set.py +++ b/howdy/src/cli/set.py @@ -9,7 +9,7 @@ import fileinput from i18n import _ # Get the absolute filepath -config_path = os.path.dirname(os.path.abspath(__file__)) + "/../config.ini" +config_path = os.path.dirname("/etc/howdy") + "/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 8dbc49a..9db2281 100644 --- a/howdy/src/cli/snap.py +++ b/howdy/src/cli/snap.py @@ -9,12 +9,11 @@ from recorders.video_capture import VideoCapture from i18n import _ -# Get the absolute path to the current directory -path = os.path.abspath(__file__ + "/..") +path = "/etc/howdy" # Read the config config = configparser.ConfigParser() -config.read(path + "/../config.ini") +config.read(path + "/config.ini") # Start video capture video_capture = VideoCapture(config) diff --git a/howdy/src/cli/test.py b/howdy/src/cli/test.py index 8933797..66a18f6 100644 --- a/howdy/src/cli/test.py +++ b/howdy/src/cli/test.py @@ -16,7 +16,7 @@ path = os.path.dirname(os.path.abspath(__file__)) # Read config from disk config = configparser.ConfigParser() -config.read(path + "/../config.ini") +config.read("/etc/howdy/config.ini") if config.get("video", "recording_plugin") != "opencv": print(_("Howdy has been configured to use a recorder which doesn't support the test command yet, aborting")) diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 3fd7f35..1e6e936 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -126,7 +126,7 @@ face_encoder = None # Try to load the face model from the models folder try: - models = json.load(open(PATH + "/models/" + user + ".dat")) + models = json.load(open("/etc/howdy/models/" + user + ".dat")) for model in models: encodings += model["data"] @@ -139,7 +139,7 @@ if len(models) < 1: # Read config from disk config = configparser.ConfigParser() -config.read(PATH + "/config.ini") +config.read("/etc/howdy/config.ini") # Get all config values needed use_cnn = config.getboolean("core", "use_cnn", fallback=False) diff --git a/howdy/src/pam.py b/howdy/src/pam.py index 5e72f76..e7b598b 100644 --- a/howdy/src/pam.py +++ b/howdy/src/pam.py @@ -11,7 +11,7 @@ import ConfigParser # Read config from disk config = ConfigParser.ConfigParser() -config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini") +config.read(os.path.dirname("/etc/howdy") + "/config.ini") def doAuth(pamh): diff --git a/howdy/src/pam/main.cc b/howdy/src/pam/main.cc index 2595c61..66c750b 100644 --- a/howdy/src/pam/main.cc +++ b/howdy/src/pam/main.cc @@ -126,7 +126,7 @@ int send_message(function Date: Tue, 5 Apr 2022 19:08:27 +0100 Subject: [PATCH 2/5] change config dir for aur pkg --- howdy/archlinux/howdy/PKGBUILD | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/howdy/archlinux/howdy/PKGBUILD b/howdy/archlinux/howdy/PKGBUILD index 4c5d32a..b3964fc 100644 --- a/howdy/archlinux/howdy/PKGBUILD +++ b/howdy/archlinux/howdy/PKGBUILD @@ -38,17 +38,17 @@ package() { # Installing the proper license files and the rest of howdy cd howdy-$pkgver install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" - mkdir -p "$pkgdir/usr/lib/security/howdy" + mkdir -p "$pkgdir/usr/etc/howdy" mkdir -p "$pkgdir/etc/howdy" - cp -r src/* "$pkgdir/usr/lib/security/howdy" + cp -r src/* "$pkgdir/usr/etc/howdy" cp -r src/config.ini "$pkgdir/etc/howdy" - cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" - cp "${srcdir}/mmod_human_face_detector.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" - cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" - chmod 600 -R "$pkgdir/usr/lib/security/howdy" + cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/etc/howdy/dlib-data/" + cp "${srcdir}/mmod_human_face_detector.dat" "$pkgdir/usr/etc/howdy/dlib-data/" + cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/etc/howdy/dlib-data/" + chmod 600 -R "$pkgdir/usr/etc/howdy" mkdir -p "$pkgdir/usr/bin" - ln -s /lib/security/howdy/cli.py "$pkgdir/usr/bin/howdy" - chmod +x "$pkgdir/usr/lib/security/howdy/cli.py" + ln -s /etc/howdy/cli.py "$pkgdir/usr/bin/howdy" + chmod +x "$pkgdir/etc/howdy/cli.py" mkdir -p "$pkgdir/usr/share/bash-completion/completions" cp autocomplete/howdy "$pkgdir/usr/share/bash-completion/completions/howdy" } From dee239a13c70ac9b2e1e612485b7bf6547ea90e7 Mon Sep 17 00:00:00 2001 From: Patrizio Bruno Date: Tue, 5 Apr 2022 19:20:00 +0100 Subject: [PATCH 3/5] gtk: search for config.ini in /etc/howdy --- howdy-gtk/src/onboarding.py | 13 +++++++------ howdy/debian/postinst | 7 ++++--- howdy/debian/preinst | 10 ++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/howdy-gtk/src/onboarding.py b/howdy-gtk/src/onboarding.py index 4ed3406..e23257f 100644 --- a/howdy-gtk/src/onboarding.py +++ b/howdy-gtk/src/onboarding.py @@ -73,17 +73,18 @@ class OnboardingWindow(gtk.Window): break else: lib_site = None - - if lib_site is None: - self.downloadoutputlabel.set_text(_("Unable to find Howdy's installation location")) - return - if os.path.exists(lib_site + "/security/howdy/dlib-data/shape_predictor_5_face_landmarks.dat"): + if lib_site: + conf_path = lib_site + "/security/howdy" + else: + conf_path = "/etc/howdy" + + if os.path.exists(conf_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"): self.downloadoutputlabel.set_text(_("Datafiles have already been downloaded!\nClick Next to continue")) self.enable_next() return - self.proc = subprocess.Popen("./install.sh", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=lib_site + "/security/howdy/dlib-data") + self.proc = subprocess.Popen("./install.sh", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=conf_path + "/howdy/dlib-data") self.download_lines = [] self.read_download_line() diff --git a/howdy/debian/postinst b/howdy/debian/postinst index 1cf7ab0..f92a7a7 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -102,9 +102,9 @@ if not os.path.exists("/tmp/howdy_picked_device"): newConf.write(configfile) # Install dlib data files if needed - if not os.path.exists("/lib/security/howdy/dlib-data/shape_predictor_5_face_landmarks.dat"): + if not os.path.exists("/lib/security/howdy/dlib-data/shape_predictor_5_face_landmarks.dat") and not os.path.exists("/etc/howdy/dlib-data/shape_predictor_5_face_landmarks.dat"): print("Attempting installation of missing data files") - handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/lib/security/howdy/dlib-data")) + handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/etc/howdy/dlib-data")) sys.exit(0) @@ -121,7 +121,7 @@ handleStatus(subprocess.call(["pip3", "install", "--upgrade", "numpy"])) log("Downloading and unpacking data files") # Run the bash script to download and unpack the .dat files needed -handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/lib/security/howdy/dlib-data")) +handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/etc/howdy/dlib-data")) log("Downloading dlib") @@ -208,6 +208,7 @@ print("Camera ID saved") # Secure the howdy folder handleStatus(sc(["chmod 744 -R /lib/security/howdy/"], shell=True)) +handleStatus(sc(["chmod 744 -R /etc/howdy/"], shell=True)) # Allow anyone to execute the python CLI os.chmod("/lib/security/howdy", 0o755) diff --git a/howdy/debian/preinst b/howdy/debian/preinst index a01628b..f0ac832 100755 --- a/howdy/debian/preinst +++ b/howdy/debian/preinst @@ -9,13 +9,19 @@ import sys if "upgrade" in sys.argv: # Try to copy the config file as a backup try: - subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + if os.path.exists("/lib/security/howdy/config.ini") and not os.path.exists("/etc/howdy/config.ini"): + subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + else os.path.exists("/etc/howdy/config.ini"): + subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) # Let the user know so he knows where to look on a failed install print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") except subprocess.CalledProcessError: try: - subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + if os.path.exists("/lib/security/howdy/config.ini") and not os.path.exists("/etc/howdy/config.ini"): + subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + else os.path.exists("/etc/howdy/config.ini"): + subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) # Let the user know so he knows where to look on a failed install print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") From 024451fd057b15bf3ce28af247f4063ef2050568 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Sun, 19 Feb 2023 10:44:04 +0100 Subject: [PATCH 4/5] Small fixes to update PR --- howdy-gtk/src/onboarding.py | 10 +-- howdy/debian/postinst | 5 -- howdy/debian/preinst | 19 ++---- howdy/src/cli/add.py | 20 +++--- howdy/src/cli/clear.py | 2 +- howdy/src/cli/list.py | 2 +- howdy/src/compare.py | 4 +- howdy/src/pam.py | 130 ------------------------------------ 8 files changed, 25 insertions(+), 167 deletions(-) delete mode 100644 howdy/src/pam.py diff --git a/howdy-gtk/src/onboarding.py b/howdy-gtk/src/onboarding.py index e23257f..d0f0e9c 100644 --- a/howdy-gtk/src/onboarding.py +++ b/howdy-gtk/src/onboarding.py @@ -64,6 +64,8 @@ class OnboardingWindow(gtk.Window): self.execute_slide5() def execute_slide1(self): + conf_path = "/etc/howdy" + self.downloadoutputlabel = self.builder.get_object("downloadoutputlabel") eventbox = self.builder.get_object("downloadeventbox") eventbox.modify_bg(gtk.StateType.NORMAL, gdk.Color(red=0, green=0, blue=0)) @@ -74,10 +76,10 @@ class OnboardingWindow(gtk.Window): else: lib_site = None - if lib_site: - conf_path = lib_site + "/security/howdy" - else: - conf_path = "/etc/howdy" + if lib_site is None: + self.downloadoutputlabel.set_text(_("Unable to find Howdy's installation location")) + return + if os.path.exists(conf_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"): self.downloadoutputlabel.set_text(_("Datafiles have already been downloaded!\nClick Next to continue")) diff --git a/howdy/debian/postinst b/howdy/debian/postinst index 1cf7b43..ebfdfdd 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -106,11 +106,6 @@ if "upgrade" in sys.argv: sys.exit(0) -log("Downloading and unpacking data files") - -# Run the bash script to download and unpack the .dat files needed -handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/etc/howdy/dlib-data")) - log("Downloading dlib") dlib_archive = "/tmp/v19.16.tar.gz" diff --git a/howdy/debian/preinst b/howdy/debian/preinst index f0ac832..1171e99 100755 --- a/howdy/debian/preinst +++ b/howdy/debian/preinst @@ -9,24 +9,17 @@ import sys if "upgrade" in sys.argv: # Try to copy the config file as a backup try: - if os.path.exists("/lib/security/howdy/config.ini") and not os.path.exists("/etc/howdy/config.ini"): - subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) - else os.path.exists("/etc/howdy/config.ini"): + # Try to copy the new location first + if os.path.exists("/etc/howdy/config.ini"): subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + # If that does not exist, try copying the old location + else: + subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) # Let the user know so he knows where to look on a failed install print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") except subprocess.CalledProcessError: - try: - if os.path.exists("/lib/security/howdy/config.ini") and not os.path.exists("/etc/howdy/config.ini"): - subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) - else os.path.exists("/etc/howdy/config.ini"): - subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) - - # Let the user know so he knows where to look on a failed install - print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") - except subprocess.CalledProcessError: - print("Could not make an backup of old Howdy config file") + print("Could not make an backup of old Howdy config file") # Don't continue setup when we're just upgrading sys.exit(0) diff --git a/howdy/src/cli/add.py b/howdy/src/cli/add.py index c4e1e8e..99104c6 100644 --- a/howdy/src/cli/add.py +++ b/howdy/src/cli/add.py @@ -26,15 +26,13 @@ except ImportError as err: # OpenCV needs to be imported after dlib import cv2 -# Get the absolute path to the current directory -path = os.path.abspath(__file__ + "/..") +# Define the absolute path to the config directory config_path = "/etc/howdy" -models_path = "/etc/howdy/models" # 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(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"): print(_("Data files have not been downloaded, please run the following commands:")) - print("\n\tcd " + os.path.realpath(path + "/../dlib-data")) + print("\n\tcd " + config_path + "/dlib-data") print("\tsudo ./install.sh\n") sys.exit(1) @@ -44,23 +42,23 @@ config.read(config_path + "/config.ini") use_cnn = config.getboolean("core", "use_cnn", fallback=False) 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(config_path + "/dlib-data/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(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") user = builtins.howdy_user # The permanent file to store the encoded model in -enc_file = models_path + "/" + user + ".dat" +enc_file = config_path + "/models/" + user + ".dat" # Known encodings encodings = [] # Make the ./models folder if it doesn't already exist -if not os.path.exists(models_path): +if not os.path.exists(config_path + "/models"): print(_("No face model folder found, creating one")) - os.makedirs(models_path) + os.makedirs(config_path + "/models") # 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 686e84a..6fa5f3e 100644 --- a/howdy/src/cli/clear.py +++ b/howdy/src/cli/clear.py @@ -30,7 +30,7 @@ if not builtins.howdy_args.y: # Abort if they don't answer y or Y if (ans.lower() != "y"): - print(_('\nInerpeting as a "NO", aborting')) + print(_('\nInterpreting as a "NO", aborting')) sys.exit(1) # Delete otherwise diff --git a/howdy/src/cli/list.py b/howdy/src/cli/list.py index ab26c4d..b079580 100644 --- a/howdy/src/cli/list.py +++ b/howdy/src/cli/list.py @@ -50,7 +50,7 @@ for enc in encodings: # Format the time as ISO in the local timezone print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(enc["time"])), end="") - # Seperate with commas again for machines, spaces otherwise + # Separate with commas again for machines, spaces otherwise print("," if builtins.howdy_args.plain else " ", end="") # End with the label diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 92bab60..f654963 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -129,7 +129,7 @@ face_encoder = None # Try to load the face model from the models folder try: - models = json.load(open("/etc/howdy/models/" + user + ".dat")) + models = json.load(open(PATH + "/models/" + user + ".dat")) for model in models: encodings += model["data"] @@ -142,7 +142,7 @@ if len(models) < 1: # Read config from disk config = configparser.ConfigParser() -config.read("/etc/howdy/config.ini") +config.read(PATH + "/config.ini") # Get all config values needed use_cnn = config.getboolean("core", "use_cnn", fallback=False) diff --git a/howdy/src/pam.py b/howdy/src/pam.py deleted file mode 100644 index e7b598b..0000000 --- a/howdy/src/pam.py +++ /dev/null @@ -1,130 +0,0 @@ -# PAM interface in python, launches compare.py - -# Import required modules -import subprocess -import os -import glob -import syslog - -# pam-python is running python 2, so we use the old module here -import ConfigParser - -# Read config from disk -config = ConfigParser.ConfigParser() -config.read(os.path.dirname("/etc/howdy") + "/config.ini") - - -def doAuth(pamh): - """Starts authentication in a seperate process""" - - # Abort if Howdy is disabled - if config.getboolean("core", "disabled"): - return pamh.PAM_AUTHINFO_UNAVAIL - - # Abort if we're in a remote SSH env - if config.getboolean("core", "ignore_ssh"): - if "SSH_CONNECTION" in os.environ or "SSH_CLIENT" in os.environ or "SSHD_OPTS" in os.environ: - return pamh.PAM_AUTHINFO_UNAVAIL - - # Abort if lid is closed - if config.getboolean("core", "ignore_closed_lid"): - if any("closed" in open(f).read() for f in glob.glob("/proc/acpi/button/lid/*/state")): - return pamh.PAM_AUTHINFO_UNAVAIL - - # Abort if the video device does not exist - if not os.path.exists(config.get("video", "device_path")): - if config.getboolean("video", "warn_no_device"): - print("Camera path is not configured correctly, please edit the 'device_path' config value.") - return pamh.PAM_AUTHINFO_UNAVAIL - - # Set up syslog - syslog.openlog("[HOWDY]", 0, syslog.LOG_AUTH) - - # Alert the user that we are doing face detection - if config.getboolean("core", "detection_notice"): - pamh.conversation(pamh.Message(pamh.PAM_TEXT_INFO, "Attempting face detection")) - - syslog.syslog(syslog.LOG_INFO, "Attempting facial authentication for user " + pamh.get_user()) - - # Run compare as python3 subprocess to circumvent python version and import issues - status = subprocess.call(["/usr/bin/python3", os.path.dirname(os.path.abspath(__file__)) + "/compare.py", pamh.get_user()]) - - # Status 10 means we couldn't find any face models - if status == 10: - if not config.getboolean("core", "suppress_unknown"): - pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "No face model known")) - - syslog.syslog(syslog.LOG_NOTICE, "Failure, no face model known") - syslog.closelog() - return pamh.PAM_USER_UNKNOWN - - # Status 11 means we exceded the maximum retry count - elif status == 11: - if config.getboolean("core", "timeout_notice"): - pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Face detection timeout reached")) - syslog.syslog(syslog.LOG_INFO, "Failure, timeout reached") - syslog.closelog() - return pamh.PAM_AUTH_ERR - - # Status 12 means we aborted - elif status == 12: - syslog.syslog(syslog.LOG_INFO, "Failure, general abort") - syslog.closelog() - return pamh.PAM_AUTH_ERR - - # Status 13 means the image was too dark - elif status == 13: - pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Face detection image too dark")) - syslog.syslog(syslog.LOG_INFO, "Failure, image too dark") - syslog.closelog() - return pamh.PAM_AUTH_ERR - - # Status 14 means a rubberstamp could not be given - elif status == 14: - pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Rubberstamp denied")) - syslog.syslog(syslog.LOG_INFO, "Failure, rubberstamp did not succeed") - syslog.closelog() - return pamh.PAM_AUTH_ERR - - # Status 1 is probably a python crash - elif status == 1: - pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Howdy encountered error, check stderr")) - syslog.syslog(syslog.LOG_INFO, "Failure, process crashed while authenticating") - syslog.closelog() - return pamh.PAM_SYSTEM_ERR - - # Status 0 is a successful exit - elif status == 0: - # Show the success message if it isn't suppressed - if not config.getboolean("core", "no_confirmation"): - pamh.conversation(pamh.Message(pamh.PAM_TEXT_INFO, "Identified face as " + pamh.get_user())) - - syslog.syslog(syslog.LOG_INFO, "Login approved") - syslog.closelog() - return pamh.PAM_SUCCESS - - # Otherwise, we can't discribe what happend but it wasn't successful - pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Unknown error: " + str(status))) - syslog.syslog(syslog.LOG_INFO, "Failure, unknown error" + str(status)) - syslog.closelog() - return pamh.PAM_SYSTEM_ERR - - -def pam_sm_authenticate(pamh, flags, args): - """Called by PAM when the user wants to authenticate, in sudo for example""" - return doAuth(pamh) - - -def pam_sm_open_session(pamh, flags, args): - """Called when starting a session, such as su""" - return doAuth(pamh) - - -def pam_sm_close_session(pamh, flags, argv): - """We don't need to clean anyting up at the end of a session, so returns true""" - return pamh.PAM_SUCCESS - - -def pam_sm_setcred(pamh, flags, argv): - """We don't need set any credentials, so returns true""" - return pamh.PAM_SUCCESS From 671ab1a4de4cc5cfc6623e518f664f903c8b4829 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Sun, 19 Feb 2023 10:45:03 +0100 Subject: [PATCH 5/5] Remove SRCINFO again --- howdy/archlinux/howdy/.SRCINFO | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 howdy/archlinux/howdy/.SRCINFO diff --git a/howdy/archlinux/howdy/.SRCINFO b/howdy/archlinux/howdy/.SRCINFO deleted file mode 100644 index 28479d0..0000000 --- a/howdy/archlinux/howdy/.SRCINFO +++ /dev/null @@ -1,27 +0,0 @@ -pkgbase = howdy - pkgdesc = Windows Hello for Linux - pkgver = 2.6.1 - pkgrel = 1 - url = https://github.com/boltgolt/howdy - arch = x86_64 - license = MIT - makedepends = cmake - makedepends = pkgfile - depends = opencv - depends = hdf5 - depends = pam-python - depends = python3 - depends = python-dlib - depends = python-numpy - backup = etc/howdy/config.ini - source = howdy-2.6.1.tar.gz::https://github.com/boltgolt/howdy/archive/v2.6.1.tar.gz - source = https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2 - source = https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2 - source = https://github.com/davisking/dlib-models/raw/master/shape_predictor_5_face_landmarks.dat.bz2 - sha256sums = f3f48599f78fd82b049539fcfc34de25c9435cad732697bdda94e85352964794 - sha256sums = abb1f61041e434465855ce81c2bd546e830d28bcbed8d27ffbe5bb408b11553a - sha256sums = db9e9e40f092c118d5eb3e643935b216838170793559515541c56a2b50d9fc84 - sha256sums = 6e787bbebf5c9efdb793f6cd1f023230c4413306605f24f299f12869f95aa472 - -pkgname = howdy -