Skip to content

Commit

Permalink
Fixed error on force re-sync when UniFi is unavailable. Implemented c…
Browse files Browse the repository at this point in the history
…heck for deprecated environment variables. Implemented check for valid UniFi usernames. Implemented UniFi username check in unifi.js. Added array.js utils
  • Loading branch information
glenndehaan committed Sep 30, 2024
1 parent f491c27 commit d653c12
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
*/
Expand Down Expand Up @@ -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!');
}
};
5 changes: 5 additions & 0 deletions modules/unifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
9 changes: 9 additions & 0 deletions utils/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Exports the array util
*/
module.exports = {
deprecated: [
'SECURITY_CODE',
'DISABLE_AUTH'
]
};

0 comments on commit d653c12

Please sign in to comment.