Skip to content

Commit

Permalink
4.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed May 28, 2019
1 parent 5523feb commit cd6988c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 6 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).

## 4.4.3 (2019-05-28)

### Notable Changes

* **Auth:** Ensure the JWT token was generated by the current instance of the UI, if not clear the token and logout ([#307](https://github.com/oznu/homebridge-config-ui-x/issues/307))

### Other Changes

* Add an on-screen warning when attempting to install/update/uninstall a plugin, or view the logs on unsupported versions of Node.js ([#305](https://github.com/oznu/homebridge-config-ui-x/issues/305))
* Added some more detailed log message to help when users are not able to login, need to reset their password, are unable to view accessories

## 4.4.2 (2019-05-19)

### Other Changes

* **Plugins:** Added extra logging to try and investigate the cause of [#299](https://github.com/oznu/homebridge-config-ui-x/issues/299)
* Provide a more detailed error with steps to resolve if the `node-pty` module fails to load (after a Node.js update for example)
* Added a warning message in the logs letting the user know if their Node.js version is to low (anything less than 8.0.0)
* Added a warning message in the logs letting the user know if their Node.js version is to low (anything less than 8.15.1)
* Updated npm dependencies

## 4.4.1 (2019-05-16)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-config-ui-x",
"version": "4.4.2",
"version": "4.4.3",
"description": "Configuration UI plugin for Homebridge",
"license": "MIT",
"author": "oznu <[email protected]>",
Expand Down
5 changes: 5 additions & 0 deletions src/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ export class AuthService {
username: user.username,
name: user.name,
admin: user.admin,
instanceId: this.configService.instanceId,
};
}
} catch (e) {
this.logger.warn(`Failed login attempt`);
this.logger.warn(`If you've forgotten your password you can reset to the default ` +
`of admin/admin by deleting the "auth.json" file (${this.configService.authPath}) and then restarting Homebridge.`);
throw new ForbiddenException();
}
}
Expand Down Expand Up @@ -81,6 +85,7 @@ export class AuthService {
username: user.username,
name: user.name,
admin: user.admin,
instanceId: this.configService.instanceId,
});

return {
Expand Down
12 changes: 12 additions & 0 deletions src/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ConfigService {
public homebridgeNoTimestamps = Boolean(process.env.UIX_LOG_NO_TIMESTAMPS);

// server env
public minimumNodeVersion = '8.15.1';
public runningInDocker = Boolean(process.env.HOMEBRIDGE_CONFIG_UI === '1');
public runningInLinux = (!this.runningInDocker && os.platform() === 'linux');
public ableToConfigureSelf = (!this.runningInDocker || semver.satisfies(process.env.CONFIG_UI_VERSION, '>=3.5.5'), { includePrerelease: true });
Expand Down Expand Up @@ -86,6 +87,8 @@ export class ConfigService {
secretKey: string;
};

public instanceId: string;

constructor() {
this.homebridgeConfig = fs.readJSONSync(this.configPath);
this.ui = Array.isArray(this.homebridgeConfig.platforms) ? this.homebridgeConfig.platforms.find(x => x.platform === 'config') : undefined;
Expand All @@ -111,6 +114,7 @@ export class ConfigService {
}

this.secrets = this.getSecrets();
this.instanceId = this.getInstanceId();
}

/**
Expand All @@ -131,6 +135,7 @@ export class ConfigService {
temperatureUnits: this.ui.tempUnits || 'c',
websocketCompatibilityMode: this.ui.websocketCompatibilityMode || false,
branding: this.branding,
instanceId: this.instanceId,
},
formAuth: Boolean(this.ui.auth !== 'none'),
theme: this.ui.theme || 'teal',
Expand Down Expand Up @@ -194,4 +199,11 @@ export class ConfigService {
return secrets;
}

/**
* Generates a public instance id from a sha256 has of the secret key
*/
private getInstanceId(): string {
return crypto.createHash('sha256').update(this.secrets.secretKey).digest('hex');
}

}
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class HomebridgeConfigUi {
.option('-T, --no-timestamp', '', () => process.env.UIX_LOG_NO_TIMESTAMPS = '1')
.parse(process.argv);

if (!semver.satisfies(process.version, '>=8.0.0')) {
log.warn(`Node.js v8.0.0 higher is required. You may experience issues running this plugin.`);
if (!semver.satisfies(process.version, '>=8.15.1')) {
const msg = `Node.js v8.15.1 higher is required. You may experience issues running this plugin running on ${process.version}.`;
log.error(msg);
log.warn(msg);
}

if (config.standalone || (
Expand Down
5 changes: 5 additions & 0 deletions src/modules/accessories/accessories.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class AccessoriesService {
* @param client
*/
public async connect(client) {
if (!this.configService.homebridgeConfig.bridge.port) {
this.logger.error(`config.json does not define a port under bridge.port`);
this.logger.error(`You can correct this automatically by going to the Config editor and clicking save and then restarting Homebridge.`);
}

let services;

// initial load
Expand Down
6 changes: 6 additions & 0 deletions src/modules/log/log.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as os from 'os';
import * as color from 'bash-color';
import * as semver from 'semver';
import * as pty from 'node-pty-prebuilt-multiarch';
import * as child_process from 'child_process';
import { Injectable } from '@nestjs/common';
Expand Down Expand Up @@ -30,6 +31,11 @@ export class LogService {
* @param client
*/
public connect(client, size) {
if (!semver.satisfies(process.version, `>=${this.configService.minimumNodeVersion}`)) {
client.emit('stdout', color.yellow(`Node.js v${this.configService.minimumNodeVersion} higher is required for ${this.configService.name}.\n\r`));
client.emit('stdout', color.yellow(`You may experience issues while running on Node.js ${process.version}.\n\r\n\r`));
}

if (this.command) {
client.emit('stdout', color.cyan(`Loading logs using "${this.configService.ui.log.method}" method...\r\n`));
client.emit('stdout', color.cyan(`CMD: ${this.command.join(' ')}\r\n\r\n`));
Expand Down
5 changes: 5 additions & 0 deletions src/modules/plugins/plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ export class PluginsService {

this.logger.log(`Running Command: ${command.join(' ')}`);

if (!semver.satisfies(process.version, `>=${this.configService.minimumNodeVersion}`)) {
client.emit('stdout', color.yellow(`Node.js v${this.configService.minimumNodeVersion} higher is required for ${this.configService.name}.\n\r`));
client.emit('stdout', color.yellow(`You may experience issues while running on Node.js ${process.version}.\n\r\n\r`));
}

client.emit('stdout', color.cyan(`USER: ${os.userInfo().username}\n\r`));
client.emit('stdout', color.cyan(`DIR: ${cwd}\n\r`));
client.emit('stdout', color.cyan(`CMD: ${command.join(' ')}\n\r\n\r`));
Expand Down
10 changes: 9 additions & 1 deletion ui/src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface UserInterface {
username?: string;
name?: string;
admin?: boolean;
instanceId?: string;
}

@Injectable()
Expand All @@ -29,8 +30,12 @@ export class AuthService {
private titleService: Title,
) {
// load the token (if present) from local storage on page init
this.init();
}

async init() {
await this.getAppSettings();
this.loadToken();
this.getAppSettings();
}

login(username: string, password: string) {
Expand Down Expand Up @@ -78,6 +83,9 @@ export class AuthService {
}
this.user = this.$jwtHelper.decodeToken(token);
this.token = token;
if (this.env.instanceId !== this.user.instanceId) {
throw new Error('Token does not match instance');
}
this.setLogoutTimer();
return true;
} catch (e) {
Expand Down

0 comments on commit cd6988c

Please sign in to comment.