Skip to content

Commit

Permalink
Merge pull request #313 from OpenHausIO/dev
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
mStirner committed Feb 25, 2023
2 parents 4e77faf + d1051bb commit 2057e70
Show file tree
Hide file tree
Showing 36 changed files with 2,741 additions and 134 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ WORKDIR /opt/OpenHaus/backend
COPY --from=builder node_modules node_modules
RUN apk --no-cache add openssl

ARG version=unknown
LABEL version=$version

ARG buildDate=unknown
LABEL buildDate=$buildDate

COPY ./build/ ./
#COPY ./package.json ./

Expand Down
28 changes: 27 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,22 @@ module.exports = function (grunt) {


grunt.registerTask("build:docker", () => {
cp.execSync(`docker build . -t openhaus/${pkg.name}:latest --build-arg version=${pkg.version}`, {

let buildArgs = [
`--build-arg version=${pkg.version}`,
`--build-arg buildDate=${Date.now()}`,
].join(" ");

cp.execSync(`docker build . -t openhaus/${pkg.name}:${pkg.version} ${buildArgs}`, {
env: process.env,
stdio: "inherit"
});

cp.execSync(`docker build . -t openhaus/${pkg.name}:latest ${buildArgs}`, {
env: process.env,
stdio: "inherit"
});

});


Expand Down Expand Up @@ -137,4 +149,18 @@ module.exports = function (grunt) {
});


grunt.registerTask("publish", () => {
[
`docker push openhaus/${pkg.name}:${pkg.version}`,
`docker push openhaus/${pkg.name}:latest`
].forEach((cmd) => {
cp.execSync(cmd, {
env: process.env,
stdio: "inherit"
});
});

});


};
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ The [docs](docs) folder is soon be removed.
For the HTTP API we provide a [postman collection](postman.json).


## Demo
There exsits a public demo: http://demo.open-haus.io<br />
It is deployed with docker and runs the frontend & backend container.<br />
The instance is rested to its default values every 10 Minutes.<br />
No authentication required, full API support.


## HTTP API
We provide a [postmann collection](./postman.json) that you can import.<br />
It containes documentation about every URL endpoint and its meaning.<br />
Get postman on https://www.postman.com/ its great tool for HTTP testing & documentation.

## Contribution
If you have questions, want to contribute or just wanna have a talk, open a new issue.

Fork this repository, apply the changes you want to make, and create a pull request.

__*Note*__: If you want to contribute, please take a look on the "documentation" repository, section "[How to document the source code](https://github.com/OpenHausIO/documentation#how-to-document-the-source-code)".

## Docker quick start:
Build the docker image:
```sh
npm run build:docker-image
```

Start a container:
```sh
docker run --rm -it --net host --name backend --env=UUID=c04a9aa6-7261-11ed-8578-cb6ee612422e --env=VAULT_MASTER_PASSWORD=Pa$$w0rd --env=USERS_JWT_SECRET=Pa$$w0rd --env=DATABASE_HOST=172.17.0.1 --env=API_AUTH_ENABLED=false openhaus/backend
```

## License
Im currently not sure, under what license i publish this work.<br />
Expand Down
41 changes: 0 additions & 41 deletions adapter/base64.js

This file was deleted.

42 changes: 0 additions & 42 deletions adapter/json.js

This file was deleted.

17 changes: 17 additions & 0 deletions backend.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=OpenHaus Backend
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/node /opt/OpenHaus/backend/index.js
WorkingDirectory=/opt/OpenHaus/backend
Restart=always
RestartSec=10
Environment=NODE_ENV=production
Environment=VAULT_MASTER_PASSWORD=Pa$$w0rd
Environment=USERS_JWT_SECRET=Pa$$w0rd
Environment=UUID=00000000-0000-0000-0000-000000000000

[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions components/devices/class.interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = class Interface {
is: "SERIAL",
then: SERIAL
}),
adapter: Joi.array().items("base64", "eiscp", "json", "raw").default(["raw"]),
adapter: Joi.array().items("eiscp", "raw").default(["raw"]),
description: Joi.string().allow(null).default(null)
});

Expand All @@ -108,7 +108,7 @@ module.exports = class Interface {

options = Object.assign({
keepAlive: true,
maxSockets: 1,
//maxSockets: 1,
keepAliveMsecs: 3000, // use this as websocket ping/pong value to detect broken connections?
}, options);

Expand Down
23 changes: 23 additions & 0 deletions components/mdns/class.mdns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class MDNS {

constructor(obj) {

Object.assign(this, obj);
this._id = String(obj._id);

Object.defineProperty(this, "_matches", {
value: [],
writable: false,
configurable: false,
enumerable: false
});

}

match(cb) {
this._matches.push(cb);
}

}

module.exports = MDNS;
90 changes: 90 additions & 0 deletions components/mdns/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const mongodb = require("mongodb");
const Joi = require("joi");

//const logger = require("../../system/logger").create("rooms");
//const COMMON_COMPONENT = require("../../system/component/common.js");
const COMPONENT = require("../../system/component/class.component.js");

const MDNS = require("./class.mdns.js");

const messageHandler = require("./message-handler.js");

/**
* @description
* Listen for mdns message and sends query requests.<br />
* This requires the "connector".
*
* The emitted message events is the parsed data received on the underlaying udp socket.
*
* @class C_MDNS
* @extends COMPONENT system/component/class.component.js
*
* @emits message Received message on udp socket; Arguments: [0]=parsed dns packet, [1]=raw udp message
*
* @link router.api.mdns.js routes/router.api.mdns.js
* @see https://en.wikipedia.org/wiki/Multicast_DNS
* @see https://www.npmjs.com/package/dns-packet
*/
class C_MDNS extends COMPONENT {

constructor() {

// inject logger, collection and schema object
super("mdns", {
_id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => {
return String(new mongodb.ObjectId());
}),
name: Joi.string().required(),
type: Joi.string().valid("SRV", "PTR", "A", "AAAA").default("A"),
timestamps: {
announced: Joi.number().allow(null).default(null)
}
}, module);

this.hooks.post("add", (data, next) => {
next(null, new MDNS(data));
});

this.collection.createIndex({
name: 1,
type: 1
}, {
unique: true
});

// handle incoming messages
// triggers registerd callback for mdns items
messageHandler(this);

}

}


// create component instance
const instance = module.exports = new C_MDNS();


// init component
// set items/build cache
instance.init((scope, ready) => {
scope.collection.find({}).toArray((err, data) => {
if (err) {

// shit...
ready(err);

} else {

data = data.map((obj) => {
return new MDNS(obj);
});

scope.items.push(...data);

// init done
ready(null);

}
});
});
Loading

0 comments on commit 2057e70

Please sign in to comment.