Fixed error on force re-sync when UniFi is unavailable. Implemented check for deprecated environment variables. Implemented check for valid UniFi usernames. Implemented UniFi username check in unifi.js. Added array.js utils

This commit is contained in:
Glenn de Haan
2024-09-30 18:35:52 +02:00
parent f491c27af4
commit d653c124e2
4 changed files with 39 additions and 0 deletions

View File

@@ -8,6 +8,11 @@ const fs = require('fs');
*/
const variables = require('./variables');
const log = require('./log');
/**
* Import own utils
*/
const array = require('../utils/array');
const logo = require('../utils/logo');
const types = require('../utils/types');
const time = require('../utils/time');
@@ -21,6 +26,15 @@ module.exports = () => {
*/
logo();
/**
* Check for deprecated strings
*/
array.deprecated.forEach((item) => {
if(typeof process.env[item] !== 'undefined') {
log.warn(`[Deprecation] '${item}' has been deprecated! Please remove this item from the environment variables and/or follow migration guides: https://github.com/glenndehaan/unifi-voucher-site#migration-guide`);
}
});
/**
* Output build version
*/
@@ -88,4 +102,11 @@ module.exports = () => {
* Log controller
*/
log.info(`[UniFi] Using Controller on: ${variables.unifiIp}:${variables.unifiPort} (Site ID: ${variables.unifiSiteId}${variables.unifiSsid !== '' ? `, SSID: ${variables.unifiSsid}` : ''})`);
/**
* Check for valid UniFi username
*/
if(variables.unifiUsername.includes('@')) {
log.error('[UniFi] Incorrect username detected! UniFi Cloud credentials are not supported!');
}
};

View File

@@ -38,6 +38,11 @@ const startSession = () => {
return;
}
if(settings.username.includes('@')) {
reject('[UniFi] Incorrect username detected! UniFi Cloud credentials are not supported!');
return;
}
// Create new UniFi controller object
controller = new unifi.Controller({
host: settings.ip,

View File

@@ -322,6 +322,10 @@ if(variables.serviceWeb) {
res.cookie('flashMessage', JSON.stringify({type: 'error', message: e}), {httpOnly: true, expires: new Date(Date.now() + 24 * 60 * 60 * 1000)}).redirect(302, `${req.headers['x-ingress-path'] ? req.headers['x-ingress-path'] : ''}/vouchers`);
});
if(!vouchers) {
return;
}
log.info('[Cache] Requesting UniFi Guests...');
const guests = await unifi.guests().catch((e) => {

9
utils/array.js Normal file
View File

@@ -0,0 +1,9 @@
/**
* Exports the array util
*/
module.exports = {
deprecated: [
'SECURITY_CODE',
'DISABLE_AUTH'
]
};