diff --git a/.dockerignore b/.dockerignore
index 6fc0670..46223d7 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -11,3 +11,11 @@ npm-debug.log
# Build files
public/dist/
+
+# Project files
+.github
+.editorconfig
+.gitignore
+docker-compose.yml
+Dockerfile
+README.md
diff --git a/README.md b/README.md
index b22679d..566549d 100644
--- a/README.md
+++ b/README.md
@@ -1,33 +1,35 @@
# UniFi Voucher Site
-A small UniFi Voucher Site for simple voucher creation
+UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers
[![Image Size](https://img.shields.io/docker/image-size/glenndehaan/unifi-voucher-site)](https://hub.docker.com/r/glenndehaan/unifi-voucher-site)
![Vouchers Overview - Desktop](https://github.com/glenndehaan/unifi-voucher-site/assets/7496187/b0d5c208-2ac7-444e-977d-31287ff19e8b)
+> Upgrading from 2.x to 3.x? Please take a look at the [migration guide](#migration-from-2x-to-3x)
+
+## Features
+
+- **Voucher Management**: Create, view, and manage vouchers with customizable options for expiration, data limits, and speeds.
+- **Web and API Services**: Access the service via a web interface or integrate with other systems using a REST API.
+- **Docker Support**: Easily deploy using Docker, with customizable environment settings.
+- **Home Assistant Add-on**: Seamlessly integrate with Home Assistant for centralized management.
+- **Receipt Printing**: Supports printing vouchers with 80mm thermal printers.
+- **Email Functionality**: Automatically send vouchers via SMTP.
+
## Structure
-- Javascript
+- NodeJS
- ExpressJS
+- EJS
- Node UniFi
- TailwindCSS
+- NodeMailer
+- PDFKit
-## Development Usage
-
-- Install NodeJS 20.0 or higher.
-- Run `npm ci` in the root folder
-- Run `npm start` & `npm run tailwind` in the root folder
+## Installation
-Then open up your favorite browser and go to http://localhost:3000/
-
-## Build Usage
-
-- Install NodeJS 20.0 or higher.
-- Run `npm ci` in the root folder
-- Run `npm run build` in the root folder
-
-## Docker
+### Docker
- Code from master is build by Docker Hub
- Builds can be pulled by using this command: `docker pull glenndehaan/unifi-voucher-site`
@@ -51,10 +53,12 @@ services:
UNIFI_PASSWORD: 'password'
# The UniFi Site ID
UNIFI_SITE_ID: 'default'
- # The 'password' used to log in to the voucher portal and used as Bearer token for the API
- SECURITY_CODE: '0000'
+ # The password used to log in to the voucher portal Web UI
+ AUTH_PASSWORD: '0000'
+ # The Bearer token used for the API
+ AUTH_TOKEN: '00000000-0000-0000-0000-000000000000'
# Disables the login/authentication for the portal and API
- DISABLE_AUTH: 'false'
+ AUTH_DISABLE: 'false'
# Voucher Types, format: expiration in minutes (required),single-use or multi-use vouchers value - '0' is for multi-use - '1' is for single-use (optional),upload speed limit in kbps (optional),download speed limit in kbps (optional),data transfer limit in MB (optional)
# To skip a parameter just but nothing in between the comma's
# After a voucher type add a semicolon, after the semicolon you can start a new voucher type
@@ -85,6 +89,30 @@ services:
> Note: When creating a Local UniFi account ensure you give 'Full Management' access rights to the Network controller. The 'Hotspot Role' won't give access to the API and therefore the application will throw errors.
+### Home Assistant Add-on
+
+For users of Home Assistant, we provide a dedicated add-on to seamlessly integrate the UniFi Voucher Site with your Home Assistant instance. This add-on simplifies the setup process and allows you to manage UniFi vouchers directly from your Home Assistant dashboard.
+
+[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fglenndehaan%2Fha-addons)
+
+#### Manual Installation
+
+To install the UniFi Voucher Site add-on for Home Assistant, follow these steps:
+
+1. Open the Supervisor panel in your Home Assistant instance.
+2. Navigate to the "Add-on Store."
+3. Add our repository to the list of repositories by clicking the three dots in the upper-right corner, then selecting "Repositories," and entering the URL of our repository: `https://github.com/glenndehaan/ha-addons`.
+4. Once the repository is added, you will find the "UniFi Voucher Site" add-on in the add-on store. Click on it.
+5. Click "Install" and wait for the installation to complete.
+
+## Development
+
+- Install NodeJS 20.0 or higher.
+- Run `npm ci` in the root folder
+- Run `npm start` & `npm run tailwind` in the root folder
+
+Then open up your favorite browser and go to http://localhost:3000/
+
## Services
The project consists of two main services: Web and API.
@@ -166,7 +194,7 @@ the different endpoints available in the API:
```
> This endpoint is protected by a security mechanism. To access it, users need to include a bearer token in the
- request authorization header. The token must match the value of the `SECURITY_CODE` environment variable. Without
+ request authorization header. The token must match the value of the `AUTH_TOKEN` environment variable. Without
this token, access to the endpoint will be denied.
4. **`/api/vouchers`**
@@ -205,25 +233,9 @@ the different endpoints available in the API:
```
> This endpoint is protected by a security mechanism. To access it, users need to include a bearer token in the
-request authorization header. The token must match the value of the `SECURITY_CODE` environment variable. Without
+request authorization header. The token must match the value of the `AUTH_TOKEN` environment variable. Without
this token, access to the endpoint will be denied.
-## Home Assistant Add-on
-
-For users of Home Assistant, we provide a dedicated add-on to seamlessly integrate the UniFi Voucher Site with your Home Assistant instance. This add-on simplifies the setup process and allows you to manage UniFi vouchers directly from your Home Assistant dashboard.
-
-[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fglenndehaan%2Fha-addons)
-
-### Installation
-
-To install the UniFi Voucher Site add-on for Home Assistant, follow these steps:
-
-1. Open the Supervisor panel in your Home Assistant instance.
-2. Navigate to the "Add-on Store."
-3. Add our repository to the list of repositories by clicking the three dots in the upper-right corner, then selecting "Repositories," and entering the URL of our repository: `https://github.com/glenndehaan/ha-addons`.
-4. Once the repository is added, you will find the "UniFi Voucher Site" add-on in the add-on store. Click on it.
-5. Click "Install" and wait for the installation to complete.
-
## Print Functionality
The UniFi Voucher Site application includes built-in support for printing vouchers using 80mm receipt printers, offering a convenient way to distribute vouchers in physical format.
@@ -304,6 +316,29 @@ Once the SMTP environment variables are configured, the email feature will be av
### Voucher Details (Mobile)
![Voucher Details - Mobile](https://github.com/glenndehaan/unifi-voucher-site/assets/7496187/28b8f97b-8042-4e6d-b1dc-8386860a1e39)
+## Migration Guide
+
+### Migration from 2.x to 3.x
+
+When upgrading from 2.x to 3.x, the following changes need to be made:
+
+1. **`SECURITY_CODE`** has been replaced by **`AUTH_PASSWORD`**.
+ - Update your environment variables configuration to use `AUTH_PASSWORD` instead of `SECURITY_CODE`.
+
+2. **`DISABLE_AUTH`** has been replaced by **`AUTH_DISABLE`**.
+ - Replace `DISABLE_AUTH` with `AUTH_DISABLE` in your environment variables.
+
+3. The API bearer token now uses a dedicated variable **`AUTH_TOKEN`**.
+ - Ensure that your API token is now stored under the `AUTH_TOKEN` variable and update your implementations to used this new token instead of the `SECURITY_CODE`.
+
+### Migration from 1.x to 2.x
+
+No migration steps are required.
+
+### Migration from Versions Prior to v1
+
+Versions before v1 do not have a direct migration path. If you are using a version earlier than v1, a fresh installation is required. Be sure to back up any important data before proceeding with a reinstall.
+
## License
MIT
diff --git a/docker-compose.yml b/docker-compose.yml
index f02fa0c..68fd1db 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,8 +10,9 @@ services:
UNIFI_USERNAME: 'admin'
UNIFI_PASSWORD: 'password'
UNIFI_SITE_ID: 'default'
- SECURITY_CODE: '0000'
- DISABLE_AUTH: 'false'
+ AUTH_PASSWORD: '0000'
+ AUTH_TOKEN: '00000000-0000-0000-0000-000000000000'
+ AUTH_DISABLE: 'false'
VOUCHER_TYPES: '480,1,,,;'
VOUCHER_CUSTOM: 'true'
SERVICE_WEB: 'true'
diff --git a/middlewares/authorization.js b/middlewares/authorization.js
index 08cf270..7bdb3b2 100644
--- a/middlewares/authorization.js
+++ b/middlewares/authorization.js
@@ -6,7 +6,7 @@ const jwt = require('../modules/jwt');
/**
* Global variables
*/
-const authDisabled = (process.env.DISABLE_AUTH === 'true') || false;
+const authDisabled = (process.env.AUTH_DISABLE === 'true') || false;
/**
* Verifies if a user is signed in
@@ -68,7 +68,7 @@ module.exports = {
}
// Check if password is correct
- const passwordCheck = req.headers.authorization === `Bearer ${(process.env.SECURITY_CODE || "0000")}`;
+ const passwordCheck = req.headers.authorization === `Bearer ${(process.env.AUTH_TOKEN || "0000")}`;
if (!passwordCheck) {
res.status(403).json({
error: 'Forbidden',
diff --git a/public/manifest.json b/public/manifest.json
index fbe2005..48f26a3 100644
--- a/public/manifest.json
+++ b/public/manifest.json
@@ -1,7 +1,7 @@
{
"name": "UniFi Voucher",
"short_name": "Voucher",
- "description": "UniFi Voucher",
+ "description": "UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers",
"icons": [
{
"src": "./images/icon/logo_192x192.png",
diff --git a/server.js b/server.js
index a210e2d..79734b9 100644
--- a/server.js
+++ b/server.js
@@ -45,7 +45,7 @@ const voucherTypes = types(config('voucher_types') || process.env.VOUCHER_TYPES
const voucherCustom = config('voucher_custom') !== null ? config('voucher_custom') : process.env.VOUCHER_CUSTOM ? process.env.VOUCHER_CUSTOM !== 'false' : true;
const webService = process.env.SERVICE_WEB ? process.env.SERVICE_WEB !== 'false' : true;
const apiService = config('service_api') || (process.env.SERVICE_API === 'true') || false;
-const authDisabled = (process.env.DISABLE_AUTH === 'true') || false;
+const authDisabled = (process.env.AUTH_DISABLE === 'true') || false;
const smtpFrom = config('smtp_from') || process.env.SMTP_FROM || '';
const smtpHost = config('smtp_host') || process.env.SMTP_HOST || '';
const smtpPort = config('smtp_port') || process.env.SMTP_PORT || 25;
@@ -199,7 +199,7 @@ if(webService) {
return;
}
- const passwordCheck = req.body.password === (process.env.SECURITY_CODE || "0000");
+ const passwordCheck = req.body.password === (process.env.AUTH_PASSWORD || "0000");
if(!passwordCheck) {
res.cookie('flashMessage', JSON.stringify({type: 'error', message: 'Password Invalid!'}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/login`);
diff --git a/template/404.ejs b/template/404.ejs
index 6b7ea7e..62e8414 100644
--- a/template/404.ejs
+++ b/template/404.ejs
@@ -8,12 +8,12 @@
-
+
-
+
diff --git a/template/login.ejs b/template/login.ejs
index 78367db..13b6cfd 100644
--- a/template/login.ejs
+++ b/template/login.ejs
@@ -8,12 +8,12 @@
-
+
-
+
diff --git a/template/voucher.ejs b/template/voucher.ejs
index 7c398bb..ba48f6f 100644
--- a/template/voucher.ejs
+++ b/template/voucher.ejs
@@ -8,12 +8,12 @@
-
+
-
+