Skip to content

Commit

Permalink
add websocket listener config (plain and ssl) (home-assistant#342)
Browse files Browse the repository at this point in the history
* add websocket listener config (plain and ssl)

* add websocket listener config (plain and ssl)

* fix syntax

* upversion to 2.0

* introduce changelog for v2.0

* Update Dockerfile
  • Loading branch information
ToSa27 authored and pvizeli committed Jul 6, 2018
1 parent e5e8bcd commit 829fa7f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions mosquitto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## 2.0
- New options to allow clients to connect through websockets
3 changes: 2 additions & 1 deletion mosquitto/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM %%BASE_IMAGE%%
ARG BUILD_FROM
FROM $BUILD_FROM

# Add env
ENV LANG C.UTF-8
Expand Down
10 changes: 8 additions & 2 deletions mosquitto/config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"name": "Mosquitto broker",
"version": "1.0",
"version": "2.0",
"slug": "mosquitto",
"description": "An Open Source MQTT broker",
"url": "https://home-assistant.io/addons/mosquitto/",
"startup": "system",
"boot": "auto",
"ports": {
"1883/tcp": 1883,
"8883/tcp": 8883
"1884/tcp": 1884,
"8883/tcp": 8883,
"8884/tcp": 8884
},
"map": ["ssl", "share"],
"options": {
"plain": true,
"plain_websockets": false,
"ssl": false,
"ssl_websockets": false,
"anonymous": true,
"logins": [],
"customize": {
Expand All @@ -25,7 +29,9 @@
},
"schema": {
"plain": "bool",
"plain_websockets": "bool",
"ssl": "bool",
"ssl_websockets": "bool",
"anonymous": "bool",
"logins": [
{"username": "str", "password": "str"}
Expand Down
23 changes: 23 additions & 0 deletions mosquitto/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ set -e
CONFIG_PATH=/data/options.json

PLAIN=$(jq --raw-output ".plain" $CONFIG_PATH)
PLAIN_WS=$(jq --raw-output ".plain_websockets" $CONFIG_PATH)
SSL=$(jq --raw-output ".ssl" $CONFIG_PATH)
SSL_WS=$(jq --raw-output ".ssl_websockets" $CONFIG_PATH)
LOGINS=$(jq --raw-output ".logins | length" $CONFIG_PATH)
ANONYMOUS=$(jq --raw-output ".anonymous" $CONFIG_PATH)
KEYFILE=$(jq --raw-output ".keyfile" $CONFIG_PATH)
Expand All @@ -13,10 +15,25 @@ CUSTOMIZE_ACTIVE=$(jq --raw-output ".customize.active" $CONFIG_PATH)

PLAIN_CONFIG="
listener 1883
protocol mqtt
"

PLAIN_WS_CONFIG="
listener 1884
protocol websockets
"

SSL_CONFIG="
listener 8883
protocol mqtt
cafile /ssl/$CERTFILE
certfile /ssl/$CERTFILE
keyfile /ssl/$KEYFILE
"

SSL_WS_CONFIG="
listener 8884
protocol websockets
cafile /ssl/$CERTFILE
certfile /ssl/$CERTFILE
keyfile /ssl/$KEYFILE
Expand All @@ -26,11 +43,17 @@ keyfile /ssl/$KEYFILE
if [ "$PLAIN" == "true" ]; then
echo "$PLAIN_CONFIG" >> /etc/mosquitto.conf
fi
if [ "$PLAIN_WS" == "true" ]; then
echo "$PLAIN_WS_CONFIG" >> /etc/mosquitto.conf
fi

# Add ssl configs
if [ "$SSL" == "true" ]; then
echo "$SSL_CONFIG" >> /etc/mosquitto.conf
fi
if [ "$SSL_WS" == "true" ]; then
echo "$SSL_WS_CONFIG" >> /etc/mosquitto.conf
fi

# Allow anonymous connections
if [ "$ANONYMOUS" == "false" ]; then
Expand Down

0 comments on commit 829fa7f

Please sign in to comment.