diff --git a/Server/Program/WebAPI.py b/Server/Program/WebAPI.py deleted file mode 100644 index d875193..0000000 --- a/Server/Program/WebAPI.py +++ /dev/null @@ -1,65 +0,0 @@ -from threading import Thread -from flask import Flask, request, jsonify -from env import * -import sqlite3 - -app = Flask(__name__) - -# Function to verify if the user is allowed to open the door -def check_access(rfid_uid, door_id): - try: - conn = sqlite3.connect(DBFILE) # Update with your database file path - cursor = conn.cursor() - - # Get the user's UPN and group memberships based on the RFID UID - cursor.execute("SELECT upn, MemberOf FROM Users WHERE rFIDUID = ?", (rfid_uid,)) - user_data = cursor.fetchone() - if user_data is None: - return False, None # User not found - - upn, user_groups = user_data - - # Get the group associated with the door - cursor.execute("SELECT GroupCn FROM Doors WHERE id = ?", (door_id,)) - door_group = cursor.fetchone() - if door_group is None: - return False, None # Door not found - - door_group = door_group[0] - - # Check if the user's group is allowed to open the door - if door_group in user_groups.split(','): - return True, upn # Access granted - else: - return False, None # Access denied - - except sqlite3.Error as e: - print(f"SQLite Error: {e}") - return False, None - -# Route to handle door access requests -@app.route('/access', methods=['POST']) -def door_access(): - data = request.get_json() - rfid_uid = data.get('rfid_uid') - door_id = data.get('door_id') - - if rfid_uid is None or door_id is None: - return jsonify({'error': 'RFID UID and door ID are required'}), 400 - - access_granted, upn = check_access(rfid_uid, door_id) - if access_granted: - return jsonify({'access_granted': True, 'upn': upn}), 200 - else: - return jsonify({'access_granted': False}), 200 - -def run_flask_app(): - app.run(debug=True, use_reloader=False, port=WebAPIPORT) -def run_webAPI_thread(): - print(f"STARTING API on port {WebAPIPORT}") - flask_thread = Thread(target=run_flask_app) - flask_thread.start() - flask_thread.join() - -if __name__ == '__main__': - app.run(debug=True) diff --git a/Server/Program/Webserver.py b/Server/Program/Webserver.py index ab3204b..e7ff170 100644 --- a/Server/Program/Webserver.py +++ b/Server/Program/Webserver.py @@ -8,19 +8,16 @@ from env import * app = Flask(__name__) - - - # Route to the home @app.route('/') -def add_door_form(): +def index(): existing_groups = get_existing_groups(DBFILE) # Update with your database file path logs = get_latest_logs(DBFILE,5) #print(logs[0]) return render_template('./index.html', existing_groups=existing_groups, logs=logs) # Route to display the fuser db @app.route('/UserDB') -def index(): +def usersdb(): users = get_users() return render_template('userdb.html', users=users) # Route to display the fuser db @@ -51,6 +48,16 @@ def export_logs(): headers={"Content-disposition": "attachment; filename=logs.csv"} ) +@app.route('/GroupsDB') +def groupsdb(): + doors = get_doors() + groups = get_existing_groups(DBFILE) + return render_template('groupsdb.html', doors=doors, groups=groups) + +@app.route('/delete_group/', methods=['POST']) +def delete_group(group_cn): + delete_group_from_database(group_cn) + return render_template('./index.html') # Route to handle form submission and add the door to the database @app.route('/add_door', methods=['POST']) def add_door(): @@ -69,7 +76,6 @@ def add_door(): def sync(): sync_ldap_to_database(DBFILE) return render_template('./LDAP.html') - redirect('/') # Route to handle door access requests diff --git a/Server/Program/database.py b/Server/Program/database.py index c2e28eb..23c74c9 100644 --- a/Server/Program/database.py +++ b/Server/Program/database.py @@ -144,7 +144,7 @@ def print_database_content(db_file): print_users_table(cursor) print_groups_table(cursor) print_doors_table(cursor) - print_log_table(cursor) + #print_log_table(cursor) conn.close() @@ -201,7 +201,21 @@ def get_existing_groups(db_file): except sqlite3.Error as e: print(f"SQLite Error: {e}") return [] - +def delete_group_from_database(group_cn): + conn = sqlite3.connect(DBFILE) + cursor = conn.cursor() + cursor.execute("DELETE FROM Groups WHERE cn = ?", (group_cn,)) + conn.commit() + conn.close() + +def get_doors(): + conn = sqlite3.connect(DBFILE) + cursor = conn.cursor() + cursor.execute("SELECT * FROM Doors") + doors = cursor.fetchall() + conn.close() + return doors + def get_users(): """ Fetch all users from the Users table in the database. @@ -215,6 +229,7 @@ def get_users(): conn.close() return users + # Function to add a door to the database def add_door_to_database(db_file, group_cn, Door_id): try: diff --git a/Server/Program/templates/groupsdb.html b/Server/Program/templates/groupsdb.html new file mode 100644 index 0000000..76da027 --- /dev/null +++ b/Server/Program/templates/groupsdb.html @@ -0,0 +1,59 @@ + + + + + + Access Logs + + + + +

Doors and Groups Associations

+

Doors

+ + + + + + + + + {% for door in doors %} + + + + + {% endfor %} + +
IDGroup CN
{{ door[0] }}{{ door[1] }}
+

Groups

+ + + + + + + + + {% for group in groups %} + + + + + {% endfor %} + +
CNAction
{{group}} +
+ +
+
+
+ + + \ No newline at end of file diff --git a/Server/Program/templates/index.html b/Server/Program/templates/index.html index c8a65e0..4c37b11 100644 --- a/Server/Program/templates/index.html +++ b/Server/Program/templates/index.html @@ -10,7 +10,9 @@

Latest Access Logs

diff --git a/Server/Program/templates/logsdb.html b/Server/Program/templates/logsdb.html index 2e40eeb..be502ec 100644 --- a/Server/Program/templates/logsdb.html +++ b/Server/Program/templates/logsdb.html @@ -44,7 +44,9 @@

Access Logs

diff --git a/Server/Program/templates/userdb.html b/Server/Program/templates/userdb.html index 4a65654..85ad079 100644 --- a/Server/Program/templates/userdb.html +++ b/Server/Program/templates/userdb.html @@ -11,7 +11,9 @@

Users Database

diff --git a/Server/Program/templates/webgui.html b/Server/Program/templates/webgui.html deleted file mode 100644 index 37011c9..0000000 --- a/Server/Program/templates/webgui.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - Add Door - - -

Add Door

-
- -

- -

- -
-
-

Force LDAP Synchronization

-
- -
- -