mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 12:08:28 +00:00
MQTT - if password isn't provided, prompt for one
Helpful for cases where you don't want to risk putting a password in the code.
This commit is contained in:
parent
52ebfa1d09
commit
9432f780f2
@ -23,6 +23,9 @@ function onMessageArrived(message) {
|
|||||||
|
|
||||||
function onFailure(err) {
|
function onFailure(err) {
|
||||||
console.error('Connection failed: ', err);
|
console.error('Connection failed: ', err);
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
document.cookie = 'mqtt_pass=';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern.prototype.mqtt = function (
|
Pattern.prototype.mqtt = function (
|
||||||
@ -35,12 +38,17 @@ Pattern.prototype.mqtt = function (
|
|||||||
) {
|
) {
|
||||||
const key = host + '-' + client;
|
const key = host + '-' + client;
|
||||||
let connected = false;
|
let connected = false;
|
||||||
|
let password_entered = false;
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
client = 'strudel-' + String(Math.floor(Math.random() * 1000000));
|
client = 'strudel-' + String(Math.floor(Math.random() * 1000000));
|
||||||
}
|
}
|
||||||
function onConnect() {
|
function onConnect() {
|
||||||
console.log('Connected to mqtt broker');
|
console.log('Connected to mqtt broker');
|
||||||
connected = true;
|
connected = true;
|
||||||
|
if (password_entered) {
|
||||||
|
document.cookie = 'mqtt_pass=' + password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cx;
|
let cx;
|
||||||
@ -58,6 +66,17 @@ Pattern.prototype.mqtt = function (
|
|||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
props.userName = username;
|
props.userName = username;
|
||||||
|
if (typeof password === 'undefined' && typeof window !== 'undefined') {
|
||||||
|
const cookie = /mqtt_pass=(\w+)/.exec(window.document.cookie);
|
||||||
|
if (cookie) {
|
||||||
|
password = cookie[1];
|
||||||
|
}
|
||||||
|
if (typeof password === 'undefined') {
|
||||||
|
password = prompt('Please enter MQTT server password');
|
||||||
|
password_entered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
props.password = password;
|
props.password = password;
|
||||||
}
|
}
|
||||||
cx.connect(props);
|
cx.connect(props);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user