mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:02 -04:00
Updated .dockerignore to remove unneeded files from container build. Updated docker-compose.yml with new environment variables. Updated README.md. Updated project description. Replaced DISABLE_AUTH with AUTH_DISABLE. Replaced SECURITY_CODE with AUTH_PASSWORD. Implemented AUTH_TOKEN for api authentication. Added migration guide.
This commit is contained in:
@@ -11,3 +11,11 @@ npm-debug.log
|
||||
|
||||
# Build files
|
||||
public/dist/
|
||||
|
||||
# Project files
|
||||
.github
|
||||
.editorconfig
|
||||
.gitignore
|
||||
docker-compose.yml
|
||||
Dockerfile
|
||||
README.md
|
||||
|
||||
109
README.md
109
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
|
||||
|
||||
[](https://hub.docker.com/r/glenndehaan/unifi-voucher-site)
|
||||
|
||||

|
||||
|
||||
> 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
|
||||
## Installation
|
||||
|
||||
- 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/
|
||||
|
||||
## 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.
|
||||
|
||||
[](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.
|
||||
|
||||
[](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)
|
||||

|
||||
|
||||
## 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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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`);
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui">
|
||||
|
||||
<meta name="description" content="UniFi Voucher">
|
||||
<meta name="description" content="UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers">
|
||||
<meta name="author" content="Glenn de Haan">
|
||||
|
||||
<meta property="og:title" content="Not Found | UniFi Voucher"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:description" content="UniFi Voucher"/>
|
||||
<meta property="og:description" content="UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers"/>
|
||||
|
||||
<link rel="manifest" href="<%= baseUrl %>/manifest.json">
|
||||
<link rel="shortcut icon" href="<%= baseUrl %>/images/favicon.ico">
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui">
|
||||
|
||||
<meta name="description" content="UniFi Voucher">
|
||||
<meta name="description" content="UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers">
|
||||
<meta name="author" content="Glenn de Haan">
|
||||
|
||||
<meta property="og:title" content="Login | UniFi Voucher"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:description" content="UniFi Voucher"/>
|
||||
<meta property="og:description" content="UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers"/>
|
||||
|
||||
<link rel="manifest" href="<%= baseUrl %>/manifest.json">
|
||||
<link rel="shortcut icon" href="<%= baseUrl %>/images/favicon.ico">
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui">
|
||||
|
||||
<meta name="description" content="UniFi Voucher">
|
||||
<meta name="description" content="UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers">
|
||||
<meta name="author" content="Glenn de Haan">
|
||||
|
||||
<meta property="og:title" content="Voucher | UniFi Voucher"/>
|
||||
<meta property="og:type" content="website"/>
|
||||
<meta property="og:description" content="UniFi Voucher"/>
|
||||
<meta property="og:description" content="UniFi Voucher Site is a web-based platform for generating and managing UniFi network guest vouchers"/>
|
||||
|
||||
<link rel="manifest" href="<%= baseUrl %>/manifest.json">
|
||||
<link rel="shortcut icon" href="<%= baseUrl %>/images/favicon.ico">
|
||||
|
||||
Reference in New Issue
Block a user