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

Some changes, revealed during release #60

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
45647e8
Very various code revork and refactoring (#29)
leechwort Dec 6, 2023
6531848
Delete file, forgotten from previous commit
leechwort Dec 6, 2023
98dd5c5
Fixed docker file and add ci for build docker images
VovaStelmashchuk Dec 7, 2023
98b5700
change to correct tag
VovaStelmashchuk Dec 7, 2023
4120558
Implement build docker image with correct tags
VovaStelmashchuk Dec 7, 2023
1e8e139
Merge pull request #36 from hacklabkyiv/fix_docker
VovaStelmashchuk Dec 7, 2023
7dca0cb
Implement creating database on start if not exist
VovaStelmashchuk Dec 14, 2023
e737cb3
Flash RFID readers from admin panel (#42)
leechwort Dec 18, 2023
02ce2e8
Fix problem with settings editor
leechwort Dec 19, 2023
78ce56a
Docker configuration changed
leechwort Dec 20, 2023
8886144
Improve plugin subsystem
leechwort Dec 21, 2023
e6c1c87
Fix UUID generator
leechwort Dec 21, 2023
169084b
Fix AddUser() bug
leechwort Dec 21, 2023
4816b7c
Some changes to login and database create logic
leechwort Dec 21, 2023
58c1099
UI fixes (#53)
temhota Jan 6, 2024
b8b51ad
Docker-related stuff changed
leechwort Jan 13, 2024
00f421b
Fix add user functionality
leechwort Jan 13, 2024
c0c9408
Some fixes (#57)
leechwort Jan 15, 2024
a9874a9
Add image and other fix (#58)
leechwort Jan 21, 2024
be74e5e
Another fixes
leechwort Jan 22, 2024
94db087
Several changes, revealed during smoke test on final stages
leechwort Feb 4, 2024
ee82a07
Added instructions steps
leechwort Feb 5, 2024
92e437c
Contributors added
leechwort Feb 5, 2024
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
47 changes: 47 additions & 0 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build Image Cross Platform

on:
workflow_dispatch:
push:
branches:
- 'master'
tags:
- '*'
pull_request:
branches:
- 'master'

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: hacklabkyiv/prismo-app

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER_NAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}

- name: Build and push
uses: docker/[email protected]
with:
context: ./
file: ./Dockerfile
platforms: linux/arm64/v8
push: true
tags: ${{ steps.meta.outputs.tags }}
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint app --disable=C0116,C0114,C0115,C0411,E0401,W0611,W0622,W0719,C0103,W1514,R0903,R1732,W0718
pylint app --disable=C0116,C0114,C0115,C0411,E0401,W0611,W0622,W0719,C0103,W1514,R0903,R1732
- name: Analysing the code with pycodestyle
run: |
pycodestyle app
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Project-specific files
external/
log.txt
*.db

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
18 changes: 12 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
FROM python:3.10-slim

FROM python:latest
WORKDIR /app
ENV PRISMO_CONFIG=/app/external/config_docker.json

RUN apt-get update && apt-get install -y jo git

COPY requirements.txt /app
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt
RUN pip3 install -r requirements.txt

COPY ./app /app

COPY . /app
# Download latest reader firmware
VOLUME ["/reader-firmware"]
RUN git clone https://github.com/hacklabkyiv/prismo-reader.git /reader-firmware

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "application:app"]
# We increase timeout here because flasher script takes long time to flash a reader device.
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "application:app", "--timeout", "600", "--workers", "4"]
155 changes: 53 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,127 +1,78 @@
![Imgur](https://i.imgur.com/V2k2seh.png)
![overview](docs/images/gen_photo.jpg "overview")

PRISMO Admin Panel
PRISMO Access system
===================

Prismo is fully open source and easy to install access system for control access of tools and equipment for maker
spaces.
PRISMO is a fully open-source and easy-to-install access system designed to
control access to tools and equipment in maker spaces. Our goal is to
create a system that any maker space in the world can easily set up for
its own use. The system is completely open-source, including the backend,
reader firmware, and PCB schematics.

The gold for the project to create a system which any maker space in the world can setup for own use. The system fully
open source, include the backend, readers firmware and PCB schema.
⚠️ ☢️ 🚀 **Attention!!! Disclaimer!!!** PRISMO is in early alpha, NOT for production use!
Expect bugs, limitations, and security risks. Use only in controlled
environments. We take no responsibility for damages. Contribute
responsibly!

## Installation by docker
## Setup on Raspberry Pi OS
Simplest way to bring PRISMO to your life is to use Raspberry Pi and graphical
desktop environment. Here is full description how to do this: [instruction](docs/rpi_installation_instructions.md)

- Install docker on the host machine.
Check [the tutorial for Raspberry Pi 4](https://github.com/codingforentrepreneurs/Pi-Awesome/blob/main/how-tos/Docker%20%26%20Docker%20Compose%20on%20Raspberry%20Pi.md)
- Create a folder `data` - the folder use for keep all persistent data, like a database.
- Run docker container:
## Reader hardware build

```bash
docker run --name=prismo-app -p 80:5000 --restart always --detach -v "$(pwd)/data/:/app/external/" hacklabkyiv/prismo-app:0.1.7
```
Readers itself has their own repository and building instructions,
follow [repo](https://github.com/hacklabkyiv/prismo-reader) to build your own beautiful reader.

Add docker to autostart:
## Reader software flashing

```bash
sudo systemctl enable docker
```
Once you got your PRISMO Reader, it is time to flash it with firmware. Flashing reader is performed from Raspberry Pi itself. To flash your brand new,
fresh reader you need to perform such steps.
1. Set correct WiFi credentials in system settings. Go go "Settings" Tab in PRISMO webapp(http://prismo.local):
![wifi settings](docs/images/wifi_settings.png "wifi settings")
2. Connect your PRISMO Reader HW to Raspberry Pi via USB Cable:
![flash reader animation](docs/images/flash_reader.webp "flash reader")
3. Reboot Raspberry Pi
4. Go to "Devices" Tab fill "Device Name" field and Press "Add Device" button.
![flash reader](docs/images/flash_reader.png "flash reader")
5. Press "Start" and wait to complete! That is all!

The application ready to work and available on `http://localhost:5000`
## Add new users to database

### The reader firmware
Ok, after flashing new reader you can add new tags and users to database.

The reader is a device which connected to the network and read RFID cards. The reader firmware is stored in
the `prismo-reader` [repository](https://github.com/hacklabkyiv/prismo-reader/tree/micropython_pn532).
1. Bring new RFID tag to PRISMO Reader. You should hear "Deny" sound and purple light signal from it.

### Configuration
![Access denied](docs/images/access_denied.webp "Access denied")

Config file name is `config.cfg`, the file located in the root directory of the project. Configs stored in YAML format.
2. Go to "Users" Tab in PRISMO App, you should see latest time of tag use. Add new user name in field below:

```
logging:
logfile: log.txt
logsize_kb: 1000
rolldepth: 3
```
![add user](docs/images/add_user.png "add user")

## Development
That is all! Now you can toggle checkbox with PRISMO Reader name, and user will have an access for this device!
But to apply changes on PRISMO Reader you need to reboot it or to use any tag again, because reader updates its keys
only during boot or after any key use.

### Preconditions
![Access Granted](docs/images/access_granted.webp "Access Granted")

- Python 3.10+ with pip
- git
- supervisor(optional)
## Contribution

### Step-by-step installation
As we said, PRISMO is in early alpha stage, a lot of improvements needed, so
contact us and join our team! We also can provide more detailed instructions about
building HW part.

1. Clone the repository:
List of contributors:

```sh
git clone [email protected]:hacklabkyiv/prismo.git
```
or by https:
```sh
git clone https://github.com/hacklabkyiv/prismo.git
```
- [Artem Synytsyn](https://github.com/leechwort)
- [Anna Deeva](https://github.com/temhota)
- [Volodymyr Stelmashchuk](https://github.com/VovaStelmashchuk)
- [Oleksandr Ivanchuk](https://github.com/Sashkoiv)
- [Volodymyr Babii](https://github.com/atari-zero)

2. Install virtualenv in project's directory:
## Financial support

```sh
$ python3 -m venv ./virtualenv
```
System is developed mainly on a volunteering basis, but finantial support for writing documentation was
given by TOLOCAR program in Ukraine: a project funded by the German Government @bmz_bund
and implemented by the GIZ with support of At Stake gGmbH in close collaboration with Ukrainian and international partners.

3. Activate virtual environment
Also, please support our hackerspace at [Patreon](https://www.patreon.com/join/HackLabKyiv) to keep our PRISMO development active!

```
source ./virtualenv/bin/activate
```

4. Install required packages:

```sh
pip3 install -r requirements.txt
```

5. Run for debugging and development: (it will reload app on code changes and enable debug mode)

```sh
export FLASK_APP=application.py
flask run --debug
```

By default, this should be run by Prismo admin process, but for debugging purpose you should run this commands by
yourself.

## Database

All information about the database is stored in [doc/database.md](docs/database.md) file.

### Logging

All logs are stored in `log.txt` file.

## API

The docs for API is stored in [docs/api.md](docs/api.md) file.

## Slack

Slack integration works with slack bot. You need to create slack bot in your slack workspace and get token for it.
Scope:

- chat:write
- files:write
- incoming-webhook

## Build docker image

The main target platform is `linux/arm64/v8` (Raspberry Pi 4). To build docker image for this platform you should use
buildx.

Execute `docker login` with hacklabkyiv credentials.
Execute this commands in the root directory of the project:

```
docker buildx create --use
docker buildx build --platform linux/arm64/v8 -t hacklabkyiv/prismo-app:<version> --push .
```
40 changes: 40 additions & 0 deletions app/api/device_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from flask import Flask, Blueprint, jsonify, request
from flask import current_app as app

from models.access_log import AccessLog
from models.device import Device

import json


device_api = Blueprint("device_api", __name__)


@device_api.route("/devices/<device_id>/accesses/", methods=["GET"])
def accesses(device_id):
data = Device.get_authorized_users(device_id)
app.ee.emit('device-updated-keys', {"device_id": device_id})
return {"keys": data}


@device_api.route("/devices/<device_id>/log_operation", methods=["POST"])
def log_operation(device_id):

json_data = request.get_json()
if not json_data:
raise Exception("Invalid request, no JSON data received")
# logging.info("Received request: " + str(json_data))

operation = json_data["operation"]
if operation not in ["lock", "unlock", "deny_access"]:
raise Exception("Invalid operation")

user_key = json_data["key"]

if (operation == "unlock") and user_key is None:
raise Exception("Invalid operation")

AccessLog.add(device_id, user_key, operation)
app.ee.emit('access-log-entry-added', {"device_id": device_id,
"user_key": user_key, "operation": operation})
return "OK", 201
Loading
Loading