diff --git a/.config.json-sample b/.config.json-sample deleted file mode 100644 index 88f67f3..0000000 --- a/.config.json-sample +++ /dev/null @@ -1,7 +0,0 @@ -{ - "mode": "capture", - "domain": { - "name": "UCTH", - "code": "ucth" - } -} \ No newline at end of file diff --git a/adebisi-fa.jpg b/adebisi-fa.jpg deleted file mode 100644 index e57576c..0000000 Binary files a/adebisi-fa.jpg and /dev/null differ diff --git a/app.py b/app.py deleted file mode 100644 index f595d48..0000000 --- a/app.py +++ /dev/null @@ -1,315 +0,0 @@ -import datetime -import json -import socketio -import uuid -import base64 -import os -import requests -from flask import Flask -import subprocess - -import gi -gi.require_version("FPrint", "2.0") -gi.require_version("Gio", "2.0") -from gi.repository import FPrint, GLib, Gio - -config = { - 'domain': { - 'name': 'UNICAL', - 'code': 'uc' - }, - 'mode': 'capture' -} -config_default = config; - -os.chdir(os.path.dirname(__file__)); - -configFileExists = os.path.exists('.config.json'); -if configFileExists: - with open('.config.json') as reader: - try: - - config = json.loads(reader.read()); - except: - config = config_default - -sio = socketio.Server(async_mode="threading") -app = Flask(__name__) -static_files = { - '/assets': './public/{}'.format(config['mode']), - '/': { 'filename': './public/{}/index.html'.format(config['mode']) } -} -app.wsgi_app = socketio.WSGIApp(sio, static_files=static_files) - -stopEnrollment = False -def progress(device, completed_stages, prnt, sessionId, error): - print({'completedStages': completed_stages, 'sessionId': sessionId}) - global stopEnrollment - if (error): - stopEnrollment = True - print({'error': error}) - else: - if (completed_stages == 5): - if (not stopEnrollment): - sio.emit("fprint-enroll-status", { 'stage': completed_stages }, room=sessionId) - else: - print('Completed with an error.') - -enroll_canceller = None; -def enroll_start(sessionId, data): - global enroll_canceller; - - ctx = FPrint.Context() - devices = ctx.get_devices() - if (len(devices) == 0): - print("There is no attached device.") - sio.emit('fprint-enroll-error', "There is no attached device."); - return; - else: - device = devices[0] - if (not device): - print("There is no attached device") - - if (not device.is_open()): - device.open_sync() - while (not device.is_open()): - print('Opening...') - try: - prt = FPrint.Print.new(device) - enroll_canceller = Gio.Cancellable.new(); - prt = device.enroll_sync(prt, enroll_canceller, progress_cb=progress, progress_data=sessionId) - img = prt.serialize() - sio.emit('fprint-enroll-done', { 'ok': True, "fingerprint": base64.b64encode(img).decode('utf-8'), 'id': str(uuid.uuid4()), 'data': data }) - except Exception as e: - print({'error': e}); - sio.emit('fprint-enroll-done', { 'ok': False, 'message': e.message}) - finally: - try: - device.close_sync() - except: - print('An error occured while closing device.'); - finally: - print('It appears device has already been removed.') - -is_verify_active = False -device = None; - -def verify_start(sessionId, data): - global device; - global is_verify_active; - - ctx = FPrint.Context() - devices = ctx.get_devices() - if (len(devices) == 0): - print("There is no attached device.") - sio.emit('fprint-verify-start-error', "There is no attached device."); - return; - else: - device = devices[0] - if (not device): - print("There is no attached device") - - if (not device.is_open()): - device.open_sync() - while (not device.is_open()): - print('Opening...') - - while True: - with open('adebisi-fa.jpg', 'r+b') as f: - img = f.read() - prtRecord = FPrint.Print.deserialize(img) - (match, prtFound) = device.verify_sync(prtRecord, Gio.Cancellable.new(), None) - if (match): - sio.emit('fprint-verify-start-done', { 'ok': True, 'data': data }, room=sessionId) - else: - sio.emit('fprint-verify-start-done', { 'ok': False }, room=sessionId) - - if not is_verify_active: - break; - - if device.is_open(): - device.close_sync() - pass - -is_identify_active = False -identify_canceller = None -raw_prints = None -def identify_start(sessionId, data): - global device; - global is_identify_active; - global identify_canceller; - global raw_prints; - - ctx = FPrint.Context() - devices = ctx.get_devices() - if (len(devices) == 0): - print("There is no attached device.") - sio.emit('fprint-identify-start-error', "There is no attached device."); - return; - else: - device = devices[0] - if (not device): - print("There is no attached device") - - if (not device.is_open()): - device.open_sync() - while (not device.is_open()): - print('Opening...') - - sio.emit('fprint-identify-start-done', room=sessionId) - is_identify_active = True - while True: - prtRecords = []; - with open('adebisi-fa.jpg', 'r+b') as f: - img = f.read() - prtRecords = [FPrint.Print.deserialize(img)] - - try: - identify_canceller = Gio.Cancellable.new(); - (match, prtFound) = device.identify_sync(prtRecords, identify_canceller, None) - if (match): - sio.emit('fprint-identify-done', { 'ok': True, 'name': 'Adebisi Foluso A.', 'phone': "+2348068287222" }, room=sessionId) - print('Found.') - else: - sio.emit('fprint-identify-done', { 'ok': False }, room=sessionId) - print('Not found.') - except: - print("Identification stopped due to error.") - sio.emit("fprint-identify-stop-done", { 'ok': True, 'message': 'Identification stopped due to error.' }) - is_identify_active = False; - finally: - if not is_identify_active: - print('Identification is active. Quiting...') - break; - pass - - if device.is_open(): - try: - device.close_sync() - except: - print('An error occured while closing device.'); - finally: - print('It appears device has already been removed.') - -# events - -@sio.on("fprint-verify-stop") -def fprint_verify_stop(sid, data): - global is_verify_active; - - if (device.is_open()): - try: - device.close_sync(); - sio.emit("fprint-verify-stop-done", { 'ok': True, 'message': 'Verifycation stopped.' }) - return; - except: - print('An error occured while closing device.'); - finally: - print("It appears device has already been removed.") - else: - sio.emit("fprint-verify-stop-done", { 'ok': False, 'message': 'Verifycation was inactive.' }) - - is_verify_active = False; - pass - - -@sio.on("fprint-verify-start") -def fprint_verify_start(sid, data): - verify_start(sid, data) - -def stop_fprint_identify(): - global is_identify_active; - global identify_canceller; - - if identify_canceller: - identify_canceller.cancel() - - sio.emit("fprint-identify-stop-done", { 'ok': True, 'message': 'Identification stopped.' }) - is_identify_active = False; - -def stop_fprint_enroll(): - global enroll_canceller; - - if enroll_canceller: - enroll_canceller.cancel() - - sio.emit("fprint-enroll-done", { 'ok': False, 'message': 'Enrollment stopped.' }) - -@sio.on("fprint-identify-start") -def fprint_identify_start(sid, data): - identify_start(sid, data) - -@sio.on("fprint-identify-stop") -def fprint_identify_stop(sid, data): - stop_fprint_identify() - -@sio.on("fprint-enroll") -def fprint_enroll_start(sid, data): - print('Enrolling {}'.format(data['finger'])) - enroll_start(sid, data) - pass - -@sio.on("fprint-enroll-stop") -def fprint_enroll_stop(sid, data): - stop_fprint_enroll() - -@sio.event -def capture(sid, data): - print(data) - pass - -@sio.event -def connect(sid, data): - global config; - config['version'] = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() - if config['mode'] == 'clockio': - global raw_prints; - stop_fprint_identify(); - config['started'] = is_identify_active - domain_code = config['domain']['code']; - response = requests.get("https://apis.a2loft.net/identity/{}/units".format(domain_code)) - config['departments'] = []; - if response.ok: - responseJson = json.loads(response.text) - if responseJson['ok']: - config['departments'] = responseJson['data']; - domain_fprint_file = '{}/fprint-sync/.{}-fprint-data.json'.format(os.getenv("HOME"), domain_code); - config['records'] = { - 'length': 0, - 'timestamp': 0 - }; - if os.path.exists(domain_fprint_file): - with open(domain_fprint_file) as f: - records = json.loads(f.read()); - raw_prints = records['profiles']; - prints_dict = {}; - for profile in raw_prints: - for index, fp in enumerate(profile['fingerprints']): - reference = profile['reference']; - finger = fp['finger'] - prints_dict['{}-{}-{}'.format(reference, finger, index+1)] = profile - config['records'] = { - 'length': len(records['profiles']), - 'timestamp': records['timestamp'] - }; - else: - stop_fprint_enroll(); - - sio.emit('config', config); - pass - -@sio.event -def disconnect(sid): - print({ 'sid': sid, 'event': 'disconnect'}); - pass - -@sio.on('capture-other') -def capture_other(sid, data): - print({ "event": "capture_other", "data": data }) - pass - -with open('/tmp/libfprint-server', 'w') as f: - f.write(str(os.getpid())); - -if __name__ == '__main__': - app.run(port=9000) \ No newline at end of file diff --git a/public/capture/app.js b/public/capture/app.js deleted file mode 100644 index ece7001..0000000 --- a/public/capture/app.js +++ /dev/null @@ -1,155 +0,0 @@ - -var app = new Vue({ - el: '#app', - data: { - step: 0, - phone: '', - domain: { code: 'uc', name: 'UNICAL' }, - errorMessage: '', - version: '', - otp: '', - busy: { - login: false, - capture: false, - }, - user: { - phone: '', - username: '', - roles: [] - }, - staff: { - reference: '' - }, - fingerDetails: { - 'right-thumb': { }, - 'right-index-finger': { } - }, - socket: null - }, - created: function () { - var userStr = localStorage.getItem("user"); - if (userStr) { - this.user = JSON.parse(userStr); - this.step = 1; - } - - this.socket = io(); - - this.socket.on("connect", () => { }) - - this.socket.on("config", (data) => { - this.domain = data.domain; - this.version = data.version; - this.device = data.device; - }); - - this.socket.on("fprint-enroll-error", (data) => { - console.log({ event: 'enroll-error', data }); - swal("Oops!", `Operation failed. ${data}.`, "error"); - this.busy.capture = false; - }); - - this.socket.on("fprint-enroll-done", (data) => { - console.log({ event: 'enroll-done', data}); - if (data.ok) { - let { id, fingerprint, data: { finger }} = data; - this.step = 1.2; - this.fingerDetails[finger] = { id, fingerprint, finger } - } - this.busy.capture = false; - }); - - this.socket.on("fprint-verify-done", (data) => { - console.log({ event: 'verify-done', data}); - }); - }, - methods: { - authenticateUrl: function (api, authenticate = true) { - return `https://apis.a2loft.net/identity${api}` + (authenticate ? `?phone=${this.user.phone}&otp=${this.otp}` : ''); - }, - login: async function () { - this.busy.login = true; - var { data } = await axios.get( - this.authenticateUrl(`/validate/uc/${this.phone}/${this.otp}`, false) - ); - this.errorMessage = ''; - if (!data.ok) - this.errorMessage = "Invalid OTP specified."; - else { - localStorage.setItem("user", JSON.stringify(data.data)); - this.user = data.data; - this.step = 1.0; - } - this.busy.login = false; - }, - logout: function () { - localStorage.removeItem("user"); - this.step = 0; - }, - loadUserByReference: async function () { - this.busy.login = true; - try { - var { data } = await axios.get( - this.authenticateUrl(`/${this.domain.code}/${this.staff.reference}`) - ); - if (!data.ok) { - swal("Oops!", `Operation failed. ${data.message}.` + this.staff.reference, "error"); - } else { - this.staff = data.data; - // this.staff.verified = false; - this.step = 1.1; - } - } finally { - this.busy.login = false; - } - }, - captureFingerPrint: async function (finger) { - this.busy.capture = true; - this.step = 1.1; - this.socket.emit("fprint-enroll", { finger }); - }, - cancelCapture: async function () { - this.socket.emit("fprint-enroll-stop", { }); - }, - saveFingerPrint: async function () { - this.busy.login = true; - try { - var fingerprints = Object.keys(this.fingerDetails).map(finger => { - return { - finger, - fingerprint: this.fingerDetails[finger].fingerprint - } - }); - - if (fingerprints.length < 2) { - swal("Oops!", 'Please capture the two fingers for this profile.', "error"); - return; - } - - var { data } = await axios.post( - this.authenticateUrl(`/${this.domain.code}/fingerprints/${this.staff.reference}`), - { fingerprints } - ); - - if (data.ok) { - swal("Saved", `Fingerprint saved for ${this.staff.name} with reference ${this.staff.reference}.`, "success"); - this.newEnrolment(); - } else { - swal("Oops!", `Operation failed. ${data.message}.` + this.staff.reference, "error"); - } - } finally { - this.busy.login = false; - } - }, - newEnrolment: function () { - this.step = 1.0; - this.busy.login = false; - this.busy.capture = false; - this.staff.reference = ""; - this.fingerDetails = { - 'right-thumb': { }, - 'right-index-finger': { } - }; - } - } -}) diff --git a/public/capture/index.html b/public/capture/index.html deleted file mode 100644 index 588d76a..0000000 --- a/public/capture/index.html +++ /dev/null @@ -1,177 +0,0 @@ - -
-