Skip to content
Permalink
Browse files

Progress

  • Loading branch information...
Florian Wendelborn
Florian Wendelborn committed Feb 22, 2017
1 parent 7ef4254 commit 6fcde49744b4f7919933e8fac8d34e5849e16d04
@@ -0,0 +1,9 @@
# SmartFlat Modules

[Back to Modules](./)

## Installation Guide

To manually install a SmartFlat module, put the module into `smartflat/modules` and run `yarn run build`. You may need to create the `modules` folder.

Afterwards restart SmartFlat and the module should work.
@@ -0,0 +1,30 @@
# Storage modules

Storage modules are used to allow SmartFlat to persist sensor & user data.

## Types

| Name | Purpose | Persistance required? |
|:---------|:---------------------------------------|:----------------------|
| users | username, password, permissions, etc. | :white_check_mark: |
| settings | SmartFlat settings. Required. | :white_check_mark: |
| devices | device configurations, not sensor data | :white_check_mark: |
| sensor | sensor data | :x: |
| logs | generic stuff like "module installed" | :x: |

## API

```javascript
export default ({api}) => ({
subscribe: {
user: async (type, id, data) => {/*...*/}
},
provide: {
user: async (type, id) => {/*...*/}
}
})
```

## Caveats

1. Multiple storage modules may subscribe to a type, but only one per type can provide data.
@@ -16,6 +16,7 @@
"dependencies": {
"bulma": "^0.3.1",
"hyperapp": "^0.5.0",
"jsonwebtoken": "^7.3.0",
"robogen": "^0.0.2",
"spirit": "^0.4.0",
"spirit-body": "^0.0.3",
@@ -2,7 +2,7 @@

> Modular real-time home automation server.
Devices are just extensions.
Devices are extensions. SmartFlat can potentially support anything.

[![Slack](https://slack.smartfl.at/badge.svg)](https://slack.smartfl.at)
[![Docker](https://img.shields.io/docker/pulls/smartflat/smartflat.svg)](https://hub.docker.com/r/smartflat/smartflat)
@@ -11,16 +11,27 @@ Devices are just extensions.

## Features

- HomeKit compatible
- WebHooks
- RaspberryPi GPIO
- Arduino I²C & Serial
- Highly Compatible:
- [HomeKit](https://github.com/smartflat/smartflat-homekit)
- [WebHooks](https://github.com/smartflat/smartflat-webhooks)
- [RaspberryPi GPIO](https://github.com/smartflat/raspberry-pi)
- [Arduino I²C & Serial](https://github.com/smartflat/smartflat-arduino)
- Modular
- Everything is a module
- Easy to extend
- Flexible
- Real-time
- Scriptable

### Modular


- Secure:
- SSL for communication
- PBKDF2 for hashing
- JWT for tokens
- [OpenSource](/license.md)
- Self-hosted
- Customizable
- Choose whatever database you want
- Get a third-party WebUI
- Own a custom device? Write your own module for it

## Extensions

@@ -38,4 +49,4 @@ yarn run build

## License

SmartFlat is released under [the MIT license](/license.md).
SmartFlat is [MIT-licensed](/license.md).
@@ -0,0 +1,13 @@
// region import

import * as session from './session'

// endregion

// region export

export default {
session
}

// endregion
@@ -0,0 +1,44 @@
// region import

import crypto from 'crypto'
import jwt from 'jsonwebtoken'

// internal

import {provide} from '../utilities/modules'

// endregion

// region crypto

const key = 'secret'
const hashPassword = async ({password, salt}) => new Promise((resolve, reject) =>
crypto.pbkdf2(key, salt, 64000, 512, 'sha512', (error, key) => error
? reject(error)
: resolve(key.toString('base64'))
)
)

// endregion

// region export

export const verify = async (token) =>
jwt.verify(token, key, {
algorithms: ['HS256']
})

export const signIn = async ({name, password}) => {
const {salt, hash} = await provide.user({name})
const realHash = await hashPassword({password, salt})

if (hash === realHash) return jwt.sign({
name
}, key, {
expiresIn: '10s'
})

throw 'wrong password'
}

// endregion

This file was deleted.

Oops, something went wrong.
@@ -1,12 +1,13 @@
// region import

import body from 'spirit-body'
import fs from 'fs'
import path from 'path'
import route from 'spirit-router'

// internal

import api from './api'
import api from '../api'

// endregion

@@ -23,11 +24,49 @@ const modules = fs

// endregion

// region provide & subscribe

export const provide = {}
export const subscribes = {
user: []
}
export const subscribe = {
user: (...args) => subscribes.user.forEach(...args)
}

modules.forEach(module => {
console.log(module)
if (module.subscribe) {
if (module.subscribe.user)
subscribes.user.push(module.subscribe.user)
}
if (module.provide) {
if (module.provide.user)
provide.user = module.provide.user
}
})

// endregion

// region serve

export default () => modules
.map(({name, routes}) => routes
.map(([method, path, dependencies, handler]) => route[method](`/m/${name}/${path}`, dependencies, handler))
.map(([method, path, dependencies, handler]) => {
if (dependencies.includes('body')) return route.wrap(
route[method](
`/m/${name}/${path}`,
dependencies,
handler
),
[body]
)
else return route[method](
`/m/${name}/${path}`,
dependencies,
handler
)
})
)
.reduce((a, b) => [...a, ...b], [])

@@ -751,6 +751,10 @@ base64-js@^1.0.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1"

base64url@2.0.0, base64url@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/base64url/-/base64url-2.0.0.tgz#eac16e03ea1438eff9423d69baa36262ed1f70bb"

bcrypt-pbkdf@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d"
@@ -862,6 +866,10 @@ browserslist@^1.0.1, browserslist@^1.4.0, browserslist@^1.5.2, browserslist@^1.7
caniuse-db "^1.0.30000624"
electron-to-chromium "^1.2.2"

buffer-equal-constant-time@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"

buffer-shims@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51"
@@ -1346,6 +1354,13 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"

ecdsa-sig-formatter@1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz#4bc926274ec3b5abb5016e7e1d60921ac262b2a1"
dependencies:
base64url "^2.0.0"
safe-buffer "^5.0.1"

electron-to-chromium@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.2.2.tgz#e41bc9488c88e3cfa1e94bde28e8420d7d47c47c"
@@ -1938,6 +1953,10 @@ isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"

isemail@1.x.x:
version "1.2.0"
resolved "https://registry.yarnpkg.com/isemail/-/isemail-1.2.0.tgz#be03df8cc3e29de4d2c5df6501263f1fa4595e9a"

isexe@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-1.1.2.tgz#36f3e22e60750920f5e7241a476a8c6a42275ad0"
@@ -1958,6 +1977,15 @@ jodid25519@^1.0.0:
dependencies:
jsbn "~0.1.0"

joi@^6.10.1:
version "6.10.1"
resolved "https://registry.yarnpkg.com/joi/-/joi-6.10.1.tgz#4d50c318079122000fe5f16af1ff8e1917b77e06"
dependencies:
hoek "2.x.x"
isemail "1.x.x"
moment "2.x.x"
topo "1.x.x"

js-base64@^2.1.9:
version "2.1.9"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce"
@@ -2022,6 +2050,16 @@ jsonpointer@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9"

jsonwebtoken@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-7.3.0.tgz#85118d6a70e3fccdf14389f4e7a1c3f9c8a9fbba"
dependencies:
joi "^6.10.1"
jws "^3.1.4"
lodash.once "^4.0.0"
ms "^0.7.1"
xtend "^4.0.1"

jsprim@^1.2.2:
version "1.3.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.3.1.tgz#2a7256f70412a29ee3670aaca625994c4dcff252"
@@ -2030,6 +2068,23 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"

jwa@^1.1.4:
version "1.1.5"
resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.1.5.tgz#a0552ce0220742cd52e153774a32905c30e756e5"
dependencies:
base64url "2.0.0"
buffer-equal-constant-time "1.0.1"
ecdsa-sig-formatter "1.0.9"
safe-buffer "^5.0.1"

jws@^3.1.4:
version "3.1.4"
resolved "https://registry.yarnpkg.com/jws/-/jws-3.1.4.tgz#f9e8b9338e8a847277d6444b1464f61880e050a2"
dependencies:
base64url "^2.0.0"
jwa "^1.1.4"
safe-buffer "^5.0.1"

kind-of@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.1.0.tgz#475d698a5e49ff5e53d14e3e732429dc8bf4cf47"
@@ -2157,6 +2212,10 @@ lodash.mergewith@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.0.tgz#150cf0a16791f5903b8891eab154609274bdea55"

lodash.once@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"

lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
@@ -2310,11 +2369,15 @@ minimist@^1.1.3, minimist@^1.2.0:
dependencies:
minimist "0.0.8"

moment@2.x.x:
version "2.17.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.17.1.tgz#fed9506063f36b10f066c8b59a144d7faebe1d82"

ms@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"

ms@0.7.2:
ms@0.7.2, ms@^0.7.1:
version "0.7.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765"

@@ -3214,6 +3277,10 @@ robogen@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/robogen/-/robogen-0.0.2.tgz#6c7ca0c289b7e3dec924bc0cbd4a386d041472ae"

safe-buffer@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"

sass-graph@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/sass-graph/-/sass-graph-2.1.2.tgz#965104be23e8103cb7e5f710df65935b317da57b"
@@ -3537,6 +3604,12 @@ to-fast-properties@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.2.tgz#f3f5c0c3ba7299a7ef99427e44633257ade43320"

topo@1.x.x:
version "1.1.0"
resolved "https://registry.yarnpkg.com/topo/-/topo-1.1.0.tgz#e9d751615d1bb87dc865db182fa1ca0a5ef536d5"
dependencies:
hoek "2.x.x"

touch@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/touch/-/touch-1.0.0.tgz#449cbe2dbae5a8c8038e30d71fa0ff464947c4de"
@@ -3771,7 +3844,7 @@ xdg-basedir@^2.0.0:
dependencies:
os-homedir "^1.0.0"

xtend@^4.0.0:
xtend@^4.0.0, xtend@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"

0 comments on commit 6fcde49

Please sign in to comment.
You can’t perform that action at this time.