forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add plugin content and update LICENSE
- v2.13.4
- v2.13.3-beta
- v2.13.2-beta
- v2.13.1-beta
- v2.13.0-beta
- v2.12.6
- v2.12.5-beta
- v2.12.4-beta
- v2.12.3-beta
- v2.12.2-beta
- v2.12.1-beta
- v2.12.0-beta
- v2.11.5
- v2.11.4-beta
- v2.11.3-beta
- v2.11.2-beta
- v2.11.1-beta
- v2.11.0-beta
- v2.10.4
- v2.10.3-beta
- v2.10.2-beta
- v2.10.1-beta
- v2.10.0-beta
- v2.9.3
- v2.9.3-beta
- v2.9.2-beta
- v2.9.1-beta
- v2.9.0-beta
- v2.8.0-beta
- v2.7.1
- v2.7.0-beta
- v2.6.0-beta
- v2.5.88
- v2.5.87
- V2_08_00
- V2_07_01_01
- V2_07_01
- V2_07_00
- V2_06_00_1
- V2_06_00
- V2_05_88_stable
- V2_05_87_stable
- V2_05_86
- V2_05_85_1
- V2_05_85
- V2_05_84_stable
- V2_05_83
- V2_05_82_1
- V2_05_82
- V2_05_81_stable
- V2_05_80
- V2_05_79
- V2_05_78
- V2_05_78_stable
- V2_05_77_1
- V2_05_77_1_stable
- V2_05_77
- V2_05_77_stable
- V2_05_76
- V2_05_75
- V2_05_74_1
- V2_05_74_1_stable
- V2_05_74
- V2_05_74_stable
- V2_05_73
- V2_05_72
- V2_05_71_2
- V2_05_71_2_stable
- V2_05_71_1
- V2_05_71_1_stable
- V2_05_71
- V2_05_71_stable
- V2_05_70
- V2_05_69
- V2_05_67_1
- V2_05_67
- V2_05_67_stable
- V2_05_66
- V2_05_65
- V2_05_65_stable
- V2_05_64
- V2_05_64_stable
- V2_05_63
- V2_05_63_stable
- V2_05_62
- V2_05_62_stable
- V2_05_61
- V2_05_61_stable
- V2_05_60
- V2_05_59
- V2_05_58
- V2_05_57
- V2_05_56
- V2_05_55
- V2_05_54
- V2_05_53
- V2_05_52
- V2_05_51
- V2_05_50
- V2_05_49
- V2_05_48
- V2_05_47
- V2_05_46
- V2_05_45
- V2_05_44
- V2_05_43
- V2_05_42
- V2_05_41
- V2_05_40
- V2_05_39
- V2_05_38
- V2_05_37
- V2_05_35
- V2_05_34
- V2_05_33
- V2_05_32
- V2_05_31
- V2_05_30
- V2_05_29
- V2_05_28
- V2_05_27
- V2_05_26
- V2_05_25
- V2_05_22
- V2_05_20
- V2_05_19
- V2_05_18
- V2_05_17
- V2_05_16
- V2_05_15
- V2_05_14
- V2_05_12
- V2_05_11
- V2_05_10
- V2_05_09
- V2_05_08
- V2_05_07
- V2_05_06
- V2_05_05
- V2_05_04
- V2_05_03
- V2_05_02
- V2_05_01
- V2_05_00
- V2_04_99
- V2_04_97
- V2_04_94
- V2_04_93
- V2_04_92
- V2_04_91
- V2_04_90
- V2_04_89
- V2_04_86
- V2_04_85
- V2_04_84
- V2_04_82
- V2_04_79
- V2_04_78
- V2_04_70
- V2_04_67
- V2_04_66
- V2_04_64
- V2_04_63
- V2_04_62
- V2_04_61
- V2_04_60
- V2_04_59
- V2_04_58
- V2_04_57
- V2_04_56
- V2_04_55
- V2_04_54
- V2_04_53
- V2_04_52
- V2_04_50
- V2_04_40
- V2_04_39
- V2_04_35
- V2_04_18
- V2_04_02
- V2_04_00
- V2_03_29
- V2_03_28
- V2_03_27
- V2_03_26
- V1_13_00
- V1_12_14
Showing
38 changed files
with
156,943 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,61 @@ | ||
deconz-rest-plugin | ||
================== | ||
Introduction | ||
============ | ||
|
||
The [deCONZ](http://www.dresden-elektronik.de/funktechnik/products/software/pc/deconz?L=1) REST plugin provides a REST API to access ZigBee Home Automation (HA) and ZigBee Light Link (ZLL) lights like dresden elektroniks [Wireless Light Control](http://www.dresden-elektronik.de/funktechnik/solutions/wireless-light-control) system and Philips Hue. | ||
|
||
As hardware the [RaspBee](http://www.dresden-elektronik.de/funktechnik/solutions/wireless-light-control/raspbee?L=1) ZigBee Shield for Raspberry Pi is used to directly communicate with the ZigBee devices. | ||
|
||
To learn more about the REST API itself please visit the [REST API Documentation](http://dresden-elektronik.github.io/deconz-rest-doc/) page. | ||
|
||
License | ||
======= | ||
The plugin is available as open source and licensed under the BSD (3-Clause) license. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
Currently the compilation of the plugin is only supported within the Raspbian distribution. | ||
|
||
##### Install deCONZ and development package | ||
1. Download deCONZ package | ||
|
||
`wget http://www.dresden-elektronik.de/rpi/deconz/deconz-latest.deb` | ||
|
||
2. Install deCONZ package | ||
|
||
`sudo dpkg -i deconz-latest.deb` | ||
|
||
3. Download deCONZ development package | ||
|
||
`wget http://www.dresden-elektronik.de/rpi/deconz-dev/deconz-dev-latest.deb` | ||
|
||
4. Install deCONZ development package | ||
|
||
`sudo dpkg -i deconz-dev-latest.deb` | ||
|
||
##### Get and compile the plugin | ||
1. Checkout the repository | ||
|
||
`git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git` | ||
|
||
2. Compile the plugin | ||
|
||
`cd deconz-rest-plugin` | ||
|
||
`qmake-qt4 && make` | ||
|
||
Hardware requirements | ||
--------------------- | ||
|
||
* Raspberry Pi | ||
* [RaspBee](http://www.dresden-elektronik.de/funktechnik/solutions/wireless-light-control/raspbee?L=1) ZigBee Shield for Raspberry Pi | ||
* or a deRFusb23e0x wireless USB dongle | ||
|
||
3rd party libraries | ||
------------------- | ||
The following libraries are used by the plugin: | ||
|
||
* [SQLite](http://www.sqlite.org) | ||
* [qt-json](https://github.com/lawand/droper/tree/master/qt-json) | ||
* [colorspace](http://www.getreuer.info/home/colorspace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (C) 2013 dresden elektronik ingenieurtechnik gmbh. | ||
* All rights reserved. | ||
* | ||
* The software in this package is published under the terms of the BSD | ||
* style license a copy of which has been included with this distribution in | ||
* the LICENSE.txt file. | ||
* | ||
*/ | ||
|
||
#include "de_web_plugin_private.h" | ||
#include <QHttpResponseHeader> | ||
#ifdef Q_OS_UNIX | ||
#include <unistd.h> | ||
#endif | ||
|
||
#ifdef Q_OS_UNIX | ||
static const char *pwsalt = "$1$8282jdkmskwiu29291"; // $1$ for MD5 | ||
#endif | ||
|
||
ApiAuth::ApiAuth() | ||
{ | ||
|
||
} | ||
|
||
/*! Init authentification and security. | ||
*/ | ||
void DeRestPluginPrivate::initAuthentification() | ||
{ | ||
bool ok = false; | ||
|
||
if (gwConfig.contains("gwusername") && gwConfig.contains("gwpassword")) | ||
{ | ||
gwAdminUserName = gwConfig["gwusername"].toString(); | ||
gwAdminPasswordHash = gwConfig["gwpassword"].toString(); | ||
|
||
if (!gwAdminUserName.isEmpty() && !gwAdminPasswordHash.isEmpty()) | ||
{ | ||
ok = true; | ||
} | ||
} | ||
|
||
if (!ok) | ||
{ | ||
// generate default username and password | ||
gwAdminUserName = "delight"; | ||
gwAdminPasswordHash = "delight"; | ||
|
||
DBG_Printf(DBG_INFO, "create default username and password\n"); | ||
|
||
// combine username:password | ||
QString comb = QString("%1:%2").arg(gwAdminUserName).arg(gwAdminPasswordHash); | ||
// create base64 encoded version as used in HTTP basic authentification | ||
QString hash = comb.toLocal8Bit().toBase64(); | ||
|
||
gwAdminPasswordHash = encryptString(hash); | ||
|
||
needSaveDatabase = true; | ||
} | ||
|
||
} | ||
|
||
/*! Use HTTP basic authentification to check if the request | ||
has valid credentials to create API key. | ||
*/ | ||
bool DeRestPluginPrivate::allowedToCreateApikey(const ApiRequest &req) | ||
{ | ||
if (req.hdr.hasKey("Authorization")) | ||
{ | ||
QStringList ls = req.hdr.value("Authorization").split(' '); | ||
if ((ls.size() > 1) && ls[0] == "Basic") | ||
{ | ||
QString enc = encryptString(ls[1]); | ||
|
||
if (enc == gwAdminPasswordHash) | ||
{ | ||
return true; | ||
} | ||
|
||
DBG_Printf(DBG_INFO, "Invalid admin password hash: %s\n", qPrintable(enc)); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/*! Checks if the request is authenticated to access the API. | ||
\retval true if authenticated | ||
\retval false if not authenticated and the rsp http status is set to 403 Forbidden and JSON error is appended | ||
*/ | ||
bool DeRestPluginPrivate::checkApikeyAuthentification(const ApiRequest &req, ApiResponse &rsp) | ||
{ | ||
QString apikey = req.apikey(); | ||
|
||
if (apikey.isEmpty()) | ||
{ | ||
return false; | ||
} | ||
|
||
std::vector<ApiAuth>::const_iterator i = apiAuths.begin(); | ||
std::vector<ApiAuth>::const_iterator end = apiAuths.end(); | ||
|
||
for (; i != end; ++i) | ||
{ | ||
if (apikey == i->apikey) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
// allow non registered devices to use the api if the link button is pressed | ||
if (gwLinkButton) | ||
{ | ||
ApiAuth auth; | ||
auth.apikey = apikey; | ||
auth.devicetype = "unknown"; | ||
apiAuths.push_back(auth); | ||
needSaveDatabase = true; | ||
return true; | ||
} | ||
|
||
rsp.httpStatus = HttpStatusForbidden; | ||
rsp.list.append(errorToMap(ERR_UNAUTHORIZED_USER, req.path.join("/"), "unauthorized user")); | ||
|
||
return false; | ||
} | ||
|
||
/*! Encrypts a string with using crypt() MD5 + salt. (unix only) | ||
\param str the input string | ||
\return the encrypted string on success or the unchanged input string on fail | ||
*/ | ||
QString DeRestPluginPrivate::encryptString(const QString &str) | ||
{ | ||
#ifdef Q_OS_UNIX | ||
// further encrypt and salt the hash | ||
const char *enc = crypt(str.toLocal8Bit().constData(), pwsalt); | ||
|
||
if (enc) | ||
{ | ||
return QString(enc); | ||
} | ||
else | ||
{ | ||
DBG_Printf(DBG_ERROR, "crypt(): %s failed\n", qPrintable(str)); | ||
// fall through and return str | ||
} | ||
|
||
#endif // Q_OS_UNIX | ||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2013 dresden elektronik ingenieurtechnik gmbh. | ||
* All rights reserved. | ||
* | ||
* The software in this package is published under the terms of the BSD | ||
* style license a copy of which has been included with this distribution in | ||
* the LICENSE.txt file. | ||
* | ||
*/ | ||
|
||
#include "de_web_plugin_private.h" | ||
|
||
void DeRestPluginPrivate::changeChannel(int channel) | ||
{ | ||
DBG_Assert(channel >= 11 && channel <= 26); | ||
|
||
if ((channel >= 11) && (channel <= 26)) | ||
{ | ||
|
||
|
||
deCONZ::ApsDataRequest req; | ||
|
||
req.setTxOptions(0); | ||
req.setDstEndpoint(0); | ||
// req.setDstAddressMode(deCONZ::ApsGroupAddress); | ||
// req.dstAddress().setGroup(groupId); | ||
req.setDstAddressMode(deCONZ::ApsNwkAddress); | ||
req.dstAddress().setNwk(0xFFFF); | ||
req.setProfileId(0x0000); // ZDP profile | ||
req.setClusterId(0x0038); // Mgmt_NWK_Update_req | ||
req.setSrcEndpoint(0); | ||
req.setRadius(0); | ||
|
||
uint8_t zdpSeq = 0x77; | ||
uint32_t scanChannels = (1 << (uint)channel); | ||
uint8_t scanDuration = 0xfe; //special value = channel change | ||
uint8_t nwkUpdateId = 0x00; | ||
|
||
QDataStream stream(&req.asdu(), QIODevice::WriteOnly); | ||
stream.setByteOrder(QDataStream::LittleEndian); | ||
stream << zdpSeq; | ||
stream << scanChannels; | ||
stream << scanDuration; | ||
stream << nwkUpdateId; | ||
|
||
deCONZ::ApsController *apsCtrl = deCONZ::ApsController::instance(); | ||
|
||
if (apsCtrl->apsdeDataRequest(req) == 0) | ||
{ | ||
DBG_Printf(DBG_INFO, "change channel to %d, channel mask = 0x%08lX\n", channel, scanChannels); | ||
} | ||
else | ||
{ | ||
DBG_Printf(DBG_ERROR, "cant send change channel\n"); | ||
} | ||
#if 0 | ||
req.setTxOptions(0); | ||
req.setDstEndpoint(0); | ||
// req.setDstAddressMode(deCONZ::ApsGroupAddress); | ||
// req.dstAddress().setGroup(groupId); | ||
req.setDstAddressMode(deCONZ::ApsExtAddress); | ||
req.dstAddress().setExt(0x17880100b829e1); // TODO: use selected node | ||
req.setProfileId(0x0000); // ZDP profile | ||
req.setClusterId(0x0034); // Mgmt_Leave_req | ||
req.setSrcEndpoint(0); | ||
req.setRadius(0); | ||
|
||
uint8_t zdpSeq = 0x77; | ||
uint64_t deviceAddress = 0; | ||
uint8_t flags = 0x00; | ||
|
||
QDataStream stream(&req.asdu(), QIODevice::WriteOnly); | ||
stream.setByteOrder(QDataStream::LittleEndian); | ||
stream << zdpSeq; | ||
stream << deviceAddress; | ||
stream << flags; | ||
|
||
if (apsCtrl->apsdeDataRequest(req) == 0) | ||
{ | ||
DBG_Printf(DBG_INFO, "send mgmt leave\n"); | ||
} | ||
else | ||
{ | ||
DBG_Printf(DBG_ERROR, "cant send mgmt leave\n"); | ||
} | ||
#endif | ||
} | ||
} |
Oops, something went wrong.