From 3863f58b410a1d462effeb142da34db25e9e05d1 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 25 Feb 2019 17:32:59 -0700 Subject: [PATCH] Update auth server docs and fix some styling --- authserver/README.md | 74 ++++++++++++++++++++++++++++++++++++++++++++ firmware/utils.h | 1 + firmware/wifi.cpp | 2 +- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/authserver/README.md b/authserver/README.md index 93e18d9..7176e95 100644 --- a/authserver/README.md +++ b/authserver/README.md @@ -78,6 +78,8 @@ Example response: { "url": "http://tools-auth.protospace.ca/tool/table-saw/", "category": "http://tools-auth.protospace.ca/category/wood-shop/", + "firmware": "0010", + "upgrade_group": "Critical", "name": "Table Saw", "slug": "table-saw", "info": "scary tool", @@ -88,6 +90,8 @@ Example response: { "url": "http://tools-auth.protospace.ca/tool/jointer/", "category": "http://tools-auth.protospace.ca/category/wood-shop/", + "firmware": "0010", + "upgrade_group": "Testing", "name": "Jointer", "slug": "jointer", "info": "goes buzz buzz", @@ -107,6 +111,8 @@ Example response: { "url": "http://tools-auth.protospace.ca/tool/metal-lathe/", "category": "http://tools-auth.protospace.ca/category/metal-shop/", + "firmware": "0010", + "upgrade_group": "Critical", "name": "Metal Lathe", "slug": "metal-lathe", "info": "spins fast", @@ -142,6 +148,38 @@ Example response: "00000B8567,00000A4123,00000C9999" ``` +#### POST `/infolog/[MAC]/` + +Send log entries to the auth server for logging. Entries are base64 encoded in the `log` param. + +Returns the number of entries processed, the current server unix time, and the firmware version for that lockout. + +Example request: + +``` +curl -d log=cHJldGVuZCB0aGF0IHRoZXNlIGFyZSBhY3R1YWwgbG9nIGVudHJpZXMgYW5kIHJhbmRvbSB0ZXh0 http://tools-auth.protospace.ca/infolog/2C3AE843A15F/ +``` + +Example response: + +``` +{ + "processed": 7, + "version": "MRWIZARD 0010 MRWIZARD", + "unixTime": 1551139854 +} +``` + +#### GET `/update/[MAC]/` + +Returns the current firmware binary that should be running on the lockout. + +Example request: + +``` +curl http://tools-auth.protospace.ca/update/2C3AE843A15F/ +``` + ### For authenticated users #### GET `/user/` @@ -168,6 +206,26 @@ Example response: ] ``` +#### PUT `/select-courses/` + +Send a list of course slugs that the user has taken in the `courses` param separated by a comma. + +This allows users to declare which courses they have taken the first time they log into the lockout website (honour system). + +Operation can only be done once. Returns the number of courses added. + +Example request: + +``` +curl -X PUT -H "Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b" -d courses=wood-1,wood-2,metal-mig http://tools-auth.protospace.ca/select-courses/ +``` + +Example response: + +``` +{"updated":3} +``` + ### For lockout admins Ensure images are square and 1280x1280 px large. Slugs should be lowercase and one word (replace spaces with hyphens). @@ -190,6 +248,14 @@ Get a specific category, modify or delete an existing one. Note: you can only delete a category that has no tools. +#### GET, POST `/course/` + +Get a list of courses, or post a new course to the database. + +#### GET, PUT, DELETE `/course/[slug]/` + +Get a specific course, modify or delete an existing one. + #### GET `/profile/` Get a list of all profiles. @@ -200,6 +266,14 @@ Get a specific profile, or modify an existing one. Here you can authorize users on tools or make them another lockout admin. +#### GET, POST `/firmware/` + +Get a version of the firmware, or post a new one to the database. + +Select which group of tools to deploy the new firmware version to, then upload a firmware .bin file. The version number is extracted from the binary data and must be unique. + +Updating firmware objects is not allowed. To assign a new tool to a firmware version, go through the tool object. + #### PUT `/update-cards/` Send a dictionary of username=card_number,card_number,card_number pairs to update any profiles already in the system. Users not already registered will be ignored. diff --git a/firmware/utils.h b/firmware/utils.h index 0dead77..d9604b8 100644 --- a/firmware/utils.h +++ b/firmware/utils.h @@ -8,6 +8,7 @@ #define CARD_CHECK_LENGTH 2 #define CARD_HEAD_BYTE 0x2 #define CARD_TAIL_BYTE 0x3 + struct __attribute__((packed)) cardData { char head; char data[CARD_DATA_LENGTH]; diff --git a/firmware/wifi.cpp b/firmware/wifi.cpp index 3e163eb..0ed134c 100644 --- a/firmware/wifi.cpp +++ b/firmware/wifi.cpp @@ -2,7 +2,7 @@ void processWifiState() { - switch(wifiState) { + switch (wifiState) { case WIFI_DISCONNECTED: commState = COMM_INIT;