Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image and other fix #58

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:latest
WORKDIR /app
ENV PRISMO_CONFIG=/app/external/config_docker.json

Expand Down
3 changes: 1 addition & 2 deletions app/api/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def api_get_user_permissions():
@web_api.route("/api/users", methods=["POST"])
def api_add_user():
user_data = request.get_json()

user = User(user_data["name"], user_data["key"], user_data.get("slack_id"))
user = User(user_data["name"], user_data["key"])

number_of_new_user_added = user.save()

Expand Down
4 changes: 3 additions & 1 deletion app/config_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"SLACK_TOKEN": "xoxb-this-is-not-areal-slack-token"
}
},
"READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/home/artsin/Dev/prismo-reader/src/flasher.sh"
"READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/home/artsin/Dev/prismo-reader/src/flasher.sh",
"WIFI_SSID": "yourSSID",
"WIFI_PASSWORD": "yourWifiPassword"
}
}
4 changes: 2 additions & 2 deletions config_default.json → app/config_docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"EXPLAIN_TEMPLATE_LOADING": false,
"PREFERRED_URL_SCHEME": "http",
"MAX_COOKIE_SIZE": 4093,
"DATABASE_URI": "file:database.db",
"DATABASE_URI": "file:./external/database.db",
"PRISMO": {
"NOTIFIER": {
"CURRENT_NOTIFIER": "SLACK",
"SLACK_CHANNEL": "#prismo-debug",
"SLACK_TOKEN": "xoxb-THIS-ISNOTAREAL-SLACKTOKEN"
},
"READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/path/to/reader/firmware/src/flasher.sh"
"READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/app/external/firmware/src/flasher.sh"
}
}
91 changes: 91 additions & 0 deletions app/static/prismo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion app/templates/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<img class="mb-4" src="/static/prismo.svg" style="max-width: 100px; height: auto;">
<h1 class="h3 mb-3 fw-normal">Login to PRISMO</h1>
<form id="loginForm" class="login-form" action="#" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
Expand Down
73 changes: 45 additions & 28 deletions app/templates/prismo/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,60 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a

<script>
let usersTable
let latestKey

document.addEventListener('DOMContentLoaded', () => {
getLatestKey().then((latestKey) => {
if (latestKey && latestKey.operation_time) {
$('#used-key-at').text(latestKey.operation_time);
} else {
console.error("Latest key data or operation_time is missing.");
// Handle the error appropriately, e.g., display a placeholder message
}
}).catch((error) => {
console.error('Error fetching latest key:', error);
// Handle the error appropriately, e.g., display an error message
});
});

async function getLatestKey() {
try {
const response = await fetch('/api/devices/latest_key')
const data = await response.json()
return data
const response = await fetch('/api/devices/latest_key');
const data = await response.json();
console.log("Latest key data:", data); // Log for debugging
return data;
} catch (error) {
console.error('Error:', error)
console.error('Error fetching latest key:', error);
return null; // Or throw an error
}
}

async function addUser(name) {
const key = latestKey.user_key
try {
const response = await fetch('/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, key })
})
console.log(response)
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
const latestKey = await getLatestKey(); // Wait for API call

if (latestKey && latestKey.user_key) {
const key = latestKey.user_key;
const response = await fetch('/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, key })
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const newData = await fetchData();
usersTable.clear().rows.add(newData).draw();
} else {
console.error("Latest key data is missing or invalid.");
// Handle the error appropriately, e.g., display a message to the user
}
// usersTable.row.add({
// name,
// key,
// operation: '<button class="btn btn-sm btn-danger" onclick="deleteUser(\'' + key + '\')">Delete</button>'
// }).draw()
const newData = await fetchData()
usersTable.clear().rows.add( newData ).draw()
} catch (error) {
console.error('Error:', error)
console.error('Error adding user:', error);
// Handle the error appropriately, e.g., display a message to the user
}
}

Expand Down Expand Up @@ -137,11 +156,9 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
columns: columns
})

latestKey = await getLatestKey()
$('#used-key-at').text(latestKey.operation_time)
}

initializeDataTable()
initializeDataTable()
</script>

{% endblock %}
10 changes: 9 additions & 1 deletion app/utils/fimware_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import subprocess
import uuid
import os
from pathlib import Path

from flask import current_app as app
Expand Down Expand Up @@ -35,8 +36,15 @@ def update_firmware_full(socket, device_id):
data = {"text": "", "progress": 0, "status": "is_running"}
try:
script_path = Path(app.config["PRISMO"]["READER_FIRMWARE_FLASHING_SCRIPT_PATH"])
# Check and set wifi credentials as environment variables. Since flasher script requires
# them as ENV variables,and looks like Raspberry Pi OS do not allows to get wifi password
# to console, this trick is used here.
run_environment = os.environ.copy()
run_environment["HOST_WIFI_SSID"] = app.config["PRISMO"]["WIFI_SSID"]
run_environment["HOST_WIFI_PASSWORD"] = app.config["PRISMO"]["WIFI_PASSWORD"]
script_cwd = script_path.parent
process = subprocess.Popen([script_path, device_id], cwd=script_cwd, stdout=subprocess.PIPE)
process = subprocess.Popen([script_path, device_id], cwd=script_cwd,
stdout=subprocess.PIPE, env=run_environment)
except FileNotFoundError:
data["text"] = "Cannot find firmware update script"
data["status"] = "Device flashing failed"
Expand Down
2 changes: 2 additions & 0 deletions config_docker_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"MAX_COOKIE_SIZE": 4093,
"DATABASE_URI": "file:./external/database.db",
"PRISMO": {
"WIFI_SSID": "yourSSID",
"WIFI_PASSWORD": "yourWifiPassword",
"ACTIVE_PLUGINS": [
"slack_notifier"
],
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ services:
volumes:
- "./data/:/app/external/"
- /run/udev:/run/udev:ro
privileged: true
devices:
# Here is some stuff to translate USB device to container.
- /dev/ttyUSB0:/dev/ttyUSB0:rw
Expand Down
6 changes: 6 additions & 0 deletions docs/slack_plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Slack Integration for PRISMO Access System
===========================================

PRISMO has an integration for access system

<a href="https://slack.com/oauth/v2/authorize?client_id=10631168368.6280904522421&scope=channels:read,chat:write&user_scope="><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack.png" srcSet="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a>
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Flask~=2.3.2
pyyaml~=6.0
Flask
pyyaml
requests
slack_sdk
Werkzeug==2.3.8
Werkzeug
flask-sock
flask-login
schedule
pylint
pycodestyle
gunicorn==20.0.4
gunicorn
argon2-cffi
pyee~=11.1.0
pyee
slack-bolt
# Used by reader flasher script
intelhex
Expand Down