diff --git a/README.md b/README.md index 775ad62..41f82af 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Windows Helloâ„¢ style authentication for Ubuntu. Use your build in IR emitters ### Installation -Fist we need to install pam-python, fswebcam and OpenCV from the Ubuntu repositories: +First we need to install pam-python, fswebcam and OpenCV from the Ubuntu repositories: ``` sudo apt install libpam-python fswebcam libopencv-dev python-opencv @@ -43,4 +43,4 @@ This script is in no way as secure as a password and will never be. Although it' To minimize the chance of this script being compromised, it's recommend to store this repo in `/etc/pam.d` and to make it read only. -DO NOT USE THIS SCRIPT AS THE SOLE AUTHENTICATION METHOD FOR YOUR SYSTEM. +DO NOT USE THIS SCRIPT AS THE SOLE AUTHENTICATION METHOD FOR YOUR SYSTEM. diff --git a/compair.py b/compair.py index ec4d8b8..fb40905 100644 --- a/compair.py +++ b/compair.py @@ -9,9 +9,9 @@ import os import json import configparser -# Read config from disk +# Read config from disk config = configparser.ConfigParser() -config.read(os.path.dirname(__file__) + "/config.ini") +config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini") def stop(status): """Stop the execution and close video stream""" @@ -34,7 +34,7 @@ tries = 0 # Try to load the face model from the models folder try: - encodings = json.load(open(os.path.dirname(__file__) + "/models/" + user + ".dat")) + encodings = json.load(open(os.path.dirname(os.path.abspath(__file__)) + "/models/" + user + ".dat")) except FileNotFoundError: sys.exit(10) diff --git a/learn.py b/learn.py index 0d50ad5..783c928 100644 --- a/learn.py +++ b/learn.py @@ -9,14 +9,19 @@ import sys import json # Import config and extra functions -import config +import configparser import utils +# Read config from disk +config = configparser.ConfigParser() +config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini") + def captureFrame(delay): """Capture and encode 1 frame of video""" + global encodings # Call fswebcam to save a frame to /tmp with a set delay - subprocess.call(["fswebcam", "-S", str(delay), "--no-banner", "-d", "/dev/video" + str(config.device_id), tmp_file], stderr=open(os.devnull, "wb")) + subprocess.call(["fswebcam", "-S", str(delay), "--no-banner", "-d", "/dev/video" + str(config.get("video", "device_id")), tmp_file], stderr=open(os.devnull, "wb")) # Get the faces in htat image ref = face_recognition.load_image_file(tmp_file) @@ -62,6 +67,8 @@ except FileNotFoundError: # If a file does exist, ask the user what needs to be done if encodings != False: encodings = utils.print_menu(encodings) +else: + encodings = [] print("\nLearning face for the user account " + user) print("Please look straight into the camera for 5 seconds") diff --git a/pam.py b/pam.py index 37c1d5d..49bcd35 100644 --- a/pam.py +++ b/pam.py @@ -10,13 +10,13 @@ import ConfigParser # Read config from disk config = ConfigParser.ConfigParser() -config.read(os.path.dirname(__file__) + "/config.ini") +config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini") def doAuth(pamh): """Start authentication in a seperate process""" # Run compair as python3 subprocess to circumvent python version and import issues - status = subprocess.call(["python3", os.path.dirname(__file__) + "/compair.py", pamh.get_user()]) + status = subprocess.call(["python3", os.path.dirname(os.path.abspath(__file__)) + "/compair.py", pamh.get_user()]) # Status 10 means we couldn't find any face models if status == 10: