Started on CLI
This commit is contained in:
parent
10563589c2
commit
590d488c34
2 changed files with 79 additions and 42 deletions
35
cli.py
Executable file
35
cli.py
Executable file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
cmd = sys.argv[1]
|
||||||
|
|
||||||
|
if cmd == "list":
|
||||||
|
if not os.path.exists(path + "/models"):
|
||||||
|
print("Face models have not been initialized yet, please run:")
|
||||||
|
print("\n\thowdy add\n")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
user = os.environ.get("USER")
|
||||||
|
enc_file = path + "/models/" + user + ".dat"
|
||||||
|
|
||||||
|
try:
|
||||||
|
encodings = json.load(open(enc_file))
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("No face model known for the current user (" + user + "), please run:")
|
||||||
|
print("\n\thowdy add\n")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("Known face models for " + user + ":")
|
||||||
|
print("\n\t\033[1;29mID Date Label\033[0m")
|
||||||
|
|
||||||
|
for enc in encodings:
|
||||||
|
print("\t" + str(enc["id"]), end="")
|
||||||
|
print((4 - len(str(enc["id"]))) * " ", end="")
|
||||||
|
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(enc["time"])), end="")
|
||||||
|
print(" " + enc["label"])
|
||||||
|
|
||||||
|
print()
|
||||||
86
installer.py
86
installer.py
|
|
@ -7,18 +7,18 @@ import fileinput
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
def log(text):
|
def log(text):
|
||||||
print("\n>>> \033[32m" + text + "\033[0m\n")
|
print("\n>>> \033[32m" + text + "\033[0m\n")
|
||||||
|
|
||||||
def handleStatus(status):
|
def handleStatus(status):
|
||||||
if (status != 0):
|
if (status != 0):
|
||||||
print("\033[31mError while running last command\033[0m")
|
print("\033[31mError while running last command\033[0m")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
user = os.getenv("SUDO_USER")
|
user = os.getenv("SUDO_USER")
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
print("Please run this script as a sudo user")
|
print("Please run this script as a sudo user")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
print("\n\033[33m HOWDY INSTALLER FOR UBUNTU\033[0m")
|
print("\n\033[33m HOWDY INSTALLER FOR UBUNTU\033[0m")
|
||||||
print(" Version 1, 2016/02/05\n")
|
print(" Version 1, 2016/02/05\n")
|
||||||
|
|
@ -34,26 +34,26 @@ devices = os.listdir("/dev")
|
||||||
picked = False
|
picked = False
|
||||||
|
|
||||||
for dev in devices:
|
for dev in devices:
|
||||||
if (dev[:5] == "video"):
|
if (dev[:5] == "video"):
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
print("Trying /dev/" + dev)
|
print("Trying /dev/" + dev)
|
||||||
|
|
||||||
sub = subprocess.Popen(["fswebcam -S 9999999999 -d /dev/" + dev + " /dev/null 2>/dev/null"], shell=True, preexec_fn=os.setsid)
|
sub = subprocess.Popen(["fswebcam -S 9999999999 -d /dev/" + dev + " /dev/null 2>/dev/null"], shell=True, preexec_fn=os.setsid)
|
||||||
|
|
||||||
print("\033[33mOne of your cameras should now be on.\033[0m")
|
print("\033[33mOne of your cameras should now be on.\033[0m")
|
||||||
ans = input("Did your IR emitters turn on? [y/N]: ")
|
ans = input("Did your IR emitters turn on? [y/N]: ")
|
||||||
|
|
||||||
os.killpg(os.getpgid(sub.pid), signal.SIGTERM)
|
os.killpg(os.getpgid(sub.pid), signal.SIGTERM)
|
||||||
|
|
||||||
if (ans.lower() == "y"):
|
if (ans.lower() == "y"):
|
||||||
picked = dev[5:]
|
picked = dev[5:]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Inerpeting as a \"NO\"\n")
|
print("Inerpeting as a \"NO\"\n")
|
||||||
|
|
||||||
if (picked == False):
|
if (picked == False):
|
||||||
print("\033[31mNo suitable IR camera found\033[0m")
|
print("\033[31mNo suitable IR camera found\033[0m")
|
||||||
|
|
||||||
log("Cloning dlib")
|
log("Cloning dlib")
|
||||||
|
|
||||||
|
|
@ -74,14 +74,16 @@ handleStatus(subprocess.call(["pip3", "install", "face_recognition"]))
|
||||||
log("Cloning howdy")
|
log("Cloning howdy")
|
||||||
|
|
||||||
if not os.path.exists("/lib/security"):
|
if not os.path.exists("/lib/security"):
|
||||||
os.makedirs("/lib/security")
|
os.makedirs("/lib/security")
|
||||||
|
|
||||||
handleStatus(subprocess.call(["git", "clone", "https://github.com/Boltgolt/howdy.git", "/lib/security/howdy"]))
|
handleStatus(subprocess.call(["git", "clone", "https://github.com/Boltgolt/howdy.git", "/lib/security/howdy"]))
|
||||||
|
|
||||||
for line in fileinput.input(["/lib/security/howdy/config.ini"], inplace = 1):
|
for line in fileinput.input(["/lib/security/howdy/config.ini"], inplace = 1):
|
||||||
print(line.replace("device_id = 1", "device_id = " + picked), end="")
|
print(line.replace("device_id = 1", "device_id = " + picked), end="")
|
||||||
|
|
||||||
handleStatus(subprocess.call(["chmod 600 -R /lib/security/howdy/"], shell=True))
|
handleStatus(subprocess.call(["chmod 600 -R /lib/security/howdy/"], shell=True))
|
||||||
|
handleStatus(subprocess.call(["ln -s /lib/security/howdy/cli.py /usr/bin/howdy"], shell=True))
|
||||||
|
handleStatus(subprocess.call(["chmod +x /usr/bin/howdy"], shell=True))
|
||||||
|
|
||||||
log("Adding howdy as PAM module")
|
log("Adding howdy as PAM module")
|
||||||
|
|
||||||
|
|
@ -90,35 +92,35 @@ printlines = []
|
||||||
inserted = False
|
inserted = False
|
||||||
|
|
||||||
with open("/etc/pam.d/common-auth") as fp:
|
with open("/etc/pam.d/common-auth") as fp:
|
||||||
line = fp.readline()
|
line = fp.readline()
|
||||||
cnt = 1
|
cnt = 1
|
||||||
while line:
|
while line:
|
||||||
outlines.append(line)
|
outlines.append(line)
|
||||||
|
|
||||||
if line[:1] != "#":
|
if line[:1] != "#":
|
||||||
printlines.append(line)
|
printlines.append(line)
|
||||||
|
|
||||||
if not inserted:
|
if not inserted:
|
||||||
line_comment = "# Howdy IR face recognition\n"
|
line_comment = "# Howdy IR face recognition\n"
|
||||||
line_Link = "auth sufficient pam_python.so /lib/security/howdy/pam.py\n\n"
|
line_Link = "auth sufficient pam_python.so /lib/security/howdy/pam.py\n\n"
|
||||||
|
|
||||||
outlines.append(line_comment)
|
outlines.append(line_comment)
|
||||||
outlines.append(line_Link)
|
outlines.append(line_Link)
|
||||||
|
|
||||||
printlines.append("\033[33m" + line_comment + "\033[0m")
|
printlines.append("\033[33m" + line_comment + "\033[0m")
|
||||||
printlines.append("\033[33m" + line_Link + "\033[0m")
|
printlines.append("\033[33m" + line_Link + "\033[0m")
|
||||||
|
|
||||||
inserted = True
|
inserted = True
|
||||||
else:
|
else:
|
||||||
printlines.append("\033[37m" + line + "\033[0m")
|
printlines.append("\033[37m" + line + "\033[0m")
|
||||||
|
|
||||||
line = fp.readline()
|
line = fp.readline()
|
||||||
cnt += 1
|
cnt += 1
|
||||||
|
|
||||||
print("\033[33m" + ">>> START OF /etc/pam.d/common-auth" + "\033[0m")
|
print("\033[33m" + ">>> START OF /etc/pam.d/common-auth" + "\033[0m")
|
||||||
|
|
||||||
for line in printlines:
|
for line in printlines:
|
||||||
print(line, end="")
|
print(line, end="")
|
||||||
|
|
||||||
print("\033[33m" + ">>> END OF /etc/pam.d/common-auth" + "\033[0m" + "\n")
|
print("\033[33m" + ">>> END OF /etc/pam.d/common-auth" + "\033[0m" + "\n")
|
||||||
|
|
||||||
|
|
@ -126,8 +128,8 @@ print("Lines will be insterted in /etc/pam.d/common-auth as shown above")
|
||||||
ans = input("Apply this change? [y/N]: ")
|
ans = input("Apply this change? [y/N]: ")
|
||||||
|
|
||||||
if (ans.lower() != "y"):
|
if (ans.lower() != "y"):
|
||||||
print("Inerpeting as a \"NO\", aborting")
|
print("Inerpeting as a \"NO\", aborting")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
print("Adding lines to PAM\n")
|
print("Adding lines to PAM\n")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue