FabLabSiegen / accesslog

Access Control and Management System for a Fab Lab
1 stars 1 forks source link

accesslog

Access and Documentation System for the Fab Lab that logs temperature data of ongoing prints, makes data available through an API and offers the possibility to control prints. It acts as an interface for printers located in the Fab Lab.

The Project is based on Django.

Table of contents

Local development

Prerequisites

  1. Latest Version of Docker and a Docker Account
  2. Check Python Version
    $ python --version
  3. If you don't have Python installed, install Python 3.9.0 or higher

    Installation

  4. Run the Docker Compose file docker-compose run --build
  5. Go to http://localhost:5000/ and follow the basic setup wizard and create an account
  6. Create a terminal in your 'web'-container and run the following commands:
$ python manage.py makemigrations
$ python manage.py migrate

This will make sure the database has all the models to work with

  1. Go to http://localhost:5000/ and under Settings > OCTOPRINT > Pluginmanager install the MQTT Plugin (by Gina Häußge)
  2. Under Settings > PLUGINS > MQTT > Broker set:
    • Host = mqtt
    • Port = 1883
    • Username = testuser
    • Passwort = testpasswd
  3. Under Settings > PLUGINS > MQTT > Topics set:
    • Basic topic = fablab/printers/testprinter/
  4. Run Docker Compose again docker-compose run --build
  5. Go to http://localhost:8000/register/ and create an Account

The Api (http://localhost:8000/api/) should now be available to you. In order to access the "Manage Printers"-tab (http://localhost:8000/manage/) you need to access the database directly and change your just created User to is_staff=true and is_superuser=true

Install PyCharm

PyCharm is a very popular and one of the best IDE for developing python application. You can download and install PyCharm by following below steps:

  1. Go to https://www.jetbrains.com/pycharm/ and select your required OS.
  2. For developing python ,download the Community version.
  3. Install PyCharm.
  4. Open PyCharm and select 'do not import settings' in the dialog box.
  5. Your Pycharm is ready for use. Select Open and choose accesslog project for development.

Testing

Run tests with the following command:

$ python manage.py test

API Endpoints

Start Print Jobs:

Example successful response:

{
    "done": false,
    "files": {
        "local": {
            "name": "boat_1HhpkoU.gcode",
            "origin": "local",
            "path": "boat_1HhpkoU.gcode",
            "refs": {
                "download": "http://octoprint:5000/downloads/files/local/boat_1HhpkoU.gcode",
                "resource": "http://octoprint:5000/api/files/local/boat_1HhpkoU.gcode"
            }
        },
        "sdcard": {
            "name": "boat_1~1.gco",
            "origin": "sdcard",
            "path": "boat_1~1.gco",
            "refs": {
                "resource": "http://octoprint:5000/api/files/sdcard/boat_1~1.gco"
            }
        }
    }
}

Stop/Cancel Print Jobs:

Example successful response:

[]

Users:

Example successful response:

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "url": "http://localhost:8000/api/users/1/",
            "username": "superuser",
            "email": "",
            "groups": []
        }
    ]
}

Groups:

Example successful response:

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "url": "http://localhost:8000/api/groups/1/",
            "name": "Testgroup"
        }
    ]
}

Models:

Example successful response (Logged in UserID:1):

[
    {
        "id": 1,
        "Name": "ghost",
        "FileName": "ghost.stl",
        "Size": "3501284",
        "File": "/upload/models/ghost_92lAXd9.stl",
        "Uploaded": "2021-10-19T10:57:44.211590+02:00",
        "Owner": 1,
        "Previous": null,
        "SharedWithUser": null
    },
    {
        "id": 2,
        "Name": "ghost",
        "FileName": "ghost.stl",
        "Size": "3501284",
        "File": "/upload/models/ghost_lsaRxE9.stl",
        "Uploaded": "2021-10-19T10:58:13.225555+02:00",
        "Owner": 1,
        "Previous": null,
        "SharedWithUser": 2
    }
]

Example successful response (?id=1, Logged in UserID:1):

{
    "id": 1,
    "Name": "ghost",
    "FileName": "ghost.stl",
    "Size": "3501284",
    "File": "/upload/models/ghost_92lAXd9.stl",
    "Uploaded": "2021-10-19T10:57:44.211590+02:00",
    "Owner": 1,
    "Previous": null,
    "SharedWithUser": null
}

Example successful response (?name=ghost, Logged in UserID:1):

[
    {
        "id": 1,
        "Name": "ghost",
        "FileName": "ghost.stl",
        "Size": "3501284",
        "File": "/upload/models/ghost_92lAXd9.stl",
        "Uploaded": "2021-10-19T10:57:44.211590+02:00",
        "Owner": 1,
        "Previous": null,
        "SharedWithUser": null
    },
    {
        "id": 2,
        "Name": "ghost",
        "FileName": "ghost.stl",
        "Size": "3501284",
        "File": "/upload/models/ghost_lsaRxE9.stl",
        "Uploaded": "2021-10-19T10:58:13.225555+02:00",
        "Owner": 1,
        "Previous": null,
        "SharedWithUser": 2
    }
]

Example successful response (MODELID=1):

{
    "id": 1,
    "Name": "ghost",
    "FileName": "ghost.stl",
    "Size": "3501284",
    "File": "http://localhost:8000/upload/models/ghost_92lAXd9.stl",
    "Uploaded": "2021-10-19T10:57:44.211590+02:00",
    "Owner": 1,
    "Previous": null,
    "SharedWithUser": null
}

Example successful response (Logged in UserID:1):

{
    "id": 7,
    "Name": "ghost",
    "FileName": "ghost.stl",
    "Size": "3501284",
    "File": "/upload/models/ghost.stl",
    "Uploaded": "2021-11-16T12:13:06.155228+01:00",
    "Owner": 1,
    "Previous": 4,
    "SharedWithUser": 2
}

GCode:

Example successful response (Logged in UserID:1):

[
    {
        "id": 8,
        "Name": "boat",
        "FileName": "boat.gcode",
        "Size": "562833",
        "File": "/upload/gcode/boat_pWiZ5oi.gcode",
        "Uploaded": "2021-11-15T12:21:47.197334+01:00",
        "UsedFilamentInG": 0.0,
        "Owner": 1,
        "UsedFilamentInMm": 0.0,
        "SharedWithUser": null,
        "EstimatedPrintingTime": "11:21:47.187739",
        "ThreeDimensionalModel": null
    },
    {
        "id": 9,
        "Name": "boat",
        "FileName": "boat.gcode",
        "Size": "562833",
        "File": "/upload/gcode/boat_1HhpkoU.gcode",
        "Uploaded": "2021-11-15T12:26:48.249209+01:00",
        "UsedFilamentInG": 123.0,
        "Owner": 1,
        "UsedFilamentInMm": 2132.0,
        "SharedWithUser": 3,
        "EstimatedPrintingTime": "12:30:00",
        "ThreeDimensionalModel": 1
    }
]

Example successful response (?id=1, Logged in UserID:1):

{
    "id": 8,
    "Name": "boat",
    "FileName": "boat.gcode",
    "Size": "562833",
    "File": "/upload/gcode/boat_pWiZ5oi.gcode",
    "Uploaded": "2021-11-15T12:21:47.197334+01:00",
    "UsedFilamentInG": 0.0,
    "Owner": 1,
    "UsedFilamentInMm": 0.0,
    "SharedWithUser": null,
    "EstimatedPrintingTime": "11:21:47.187739",
    "ThreeDimensionalModel": null
}

Example successful response (?name=boat, Logged in UserID:1):

[
    {
        "id": 8,
        "Name": "boat",
        "FileName": "boat.gcode",
        "Size": "562833",
        "File": "/upload/gcode/boat_pWiZ5oi.gcode",
        "Uploaded": "2021-11-15T12:21:47.197334+01:00",
        "UsedFilamentInG": 0.0,
        "Owner": 1,
        "UsedFilamentInMm": 0.0,
        "SharedWithUser": null,
        "EstimatedPrintingTime": "11:21:47.187739",
        "ThreeDimensionalModel": null
    },
    {
        "id": 9,
        "Name": "boat",
        "FileName": "boat.gcode",
        "Size": "562833",
        "File": "/upload/gcode/boat_1HhpkoU.gcode",
        "Uploaded": "2021-11-15T12:26:48.249209+01:00",
        "UsedFilamentInG": 123.0,
        "Owner": 1,
        "UsedFilamentInMm": 2132.0,
        "SharedWithUser": 3,
        "EstimatedPrintingTime": "12:30:00",
        "ThreeDimensionalModel": 1
    }
]

Example successful response (MODELID=8):

{
    "id": 8,
    "Name": "boat",
    "FileName": "boat.gcode",
    "Size": "562833",
    "File": "http://localhost:8000/upload/gcode/boat_pWiZ5oi.gcode",
    "Uploaded": "2021-11-15T12:21:47.197334+01:00",
    "UsedFilamentInG": 0.0,
    "Owner": 1,
    "UsedFilamentInMm": 0.0,
    "SharedWithUser": null,
    "EstimatedPrintingTime": "11:21:47.187739",
    "ThreeDimensionalModel": null
}

Example successful response (Logged in UserID:1):

{
    "id": 10,
    "Name": "boat",
    "FileName": "boat.gcode",
    "Size": "562833",
    "File": "/upload/gcode/boat_H4zM6xZ.gcode",
    "Uploaded": "2021-11-16T13:43:18.135579+01:00",
    "UsedFilamentInG": 123.0,
    "Owner": 1,
    "UsedFilamentInMm": 12323.0,
    "SharedWithUser": 3,
    "EstimatedPrintingTime": "12:33:00",
    "ThreeDimensionalModel": 3
}

Slicing Configs:

Example successful response:

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "Config": [
                {
                    "dummy0": "1-770-736-8031 x56442",
                    "dummy1": 1,
                    "dummy2": "Leanne Graham",
                    "dummy3": "Bret",
                    "dummy4": "Sincere@april.biz"
                }
            ],
            "GCode": 10
        },
        {
            "Config": [
                {
                    "dummy0": "1-770-736-8031 x56442",
                    "dummy1": 1,
                    "dummy2": "Leanne Graham",
                    "dummy3": "Bret",
                    "dummy4": "Sincere@april.biz"
                }
            ],
            "GCode": 9
        }
    ]
}

Example successful response:

[
    {
        "dummy0": "1-770-736-8031 x56442",
        "dummy1": 1,
        "dummy2": "Leanne Graham",
        "dummy3": "Bret",
        "dummy4": "Sincere@april.biz"
    }
]

Example successful response (returns saved JSON Config):

[
    {
        "dummy0": "1-770-736-8031 x56442",
        "dummy1": 1,
        "dummy2": "Leanne Graham",
        "dummy3": "Bret",
        "dummy4": "Sincere@april.biz"
    }
]

Print Jobs:

Example successful response (Logged in UserID:1):

[
    {
        "id": 1478,
        "User": 1,
        "Machine": 17,
        "GCode": 9,
        "Start": "2021-11-15T17:12:42.932473+01:00",
        "End": "2021-11-15T17:17:37.710299+01:00",
        "State": 0
    },
    {
        "id": 1479,
        "User": 1,
        "Machine": 17,
        "GCode": 9,
        "Start": "2021-11-15T17:19:38.623075+01:00",
        "End": "2021-11-15T17:24:33.783123+01:00",
        "State": 0
    }
]

Example successful response (PRINTJOBID:1476):

{
    "id": 1476,
    "User": 1,
    "Machine": 17,
    "GCode": 9,
    "Start": "2021-11-15T16:04:04.274812+01:00",
    "End": "2021-11-15T16:04:04.274820+01:00",
    "State": 0
}

Example successful response (Logged in UserID:1):

{
    "id": 1494,
    "User": 1,
    "Machine": 12,
    "GCode": 10,
    "Start": "2021-11-17T10:51:00+01:00",
    "End": "2021-11-17T10:53:00+01:00",
    "State": 0
}

Print Media Files:

Example successful response:

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 5,
            "PrintJob": 1478,
            "File": "http://localhost:8000/upload/printmedia/New_York_City_High-Quality_Wallpaper_Pack.jpg",
            "Owner": 1
        }
    ]
}

Example successful response:

{
    "id": 5,
    "PrintJob": 1478,
    "File": "http://localhost:8000/upload/printmedia/New_York_City_High-Quality_Wallpaper_Pack.jpg",
    "Owner": 1
}

Example successful response:

[
    {
        "id": 5,
        "PrintJob": 1478,
        "File": "/upload/printmedia/New_York_City_High-Quality_Wallpaper_Pack.jpg",
        "Owner": 1
    }
]

Example successful response (Logged in UserID:1):

{
    "id": 5,
    "PrintJob": 1478,
    "File": "http://localhost:8000/upload/printmedia/New_York_City_High-Quality_Wallpaper_Pack.jpg",
    "Owner": 1
}

Future improvement possibilities

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.