domitcz: fix dzVents scripts

Domoticz 3.8153 introduced support for dzVents. Unfortunately this was
broken by the 902_add-scripts-path, which attempts to make Domoticz more
FHS-compliant instead of throwing everything under /opt/domoticz.

The problem is that dzVents scripts added via the webinterface will be
generated on the filesystem. With the 902_add-scripts-path patch,
Domoticz tried to write this to "scriptsdir/dzVents/generated_scripts".
As the scriptsdir contains scripts that come with upstream, and are not
meant to be changed, this defaults to /usr/share/domoticz/scripts, which
is not writeable, so Domoticz is unable to write the script to the
filesystem. What is worse is that this silently fails.

Fix this by moving the generated_scripts dir to
"userdatadir/generated_scripts". The userdatadir defaults to
/var/lib/domoticz, which is writeable.

Additionally, since this patch does more than just adding the scripts
path, rename it to something more appropriate.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
This commit is contained in:
Stijn Tintel 2017-09-19 22:13:44 +03:00
parent 3fcbbbf500
commit 476dae33c7
4 changed files with 128 additions and 63 deletions

View File

@ -11,7 +11,7 @@ PKG_NAME:=domoticz
PKG_VERSION_MAJOR:=3 PKG_VERSION_MAJOR:=3
PKG_VERSION_PATCH:=8153 PKG_VERSION_PATCH:=8153
PKG_VERSION:=$(PKG_VERSION_MAJOR).$(PKG_VERSION_PATCH) PKG_VERSION:=$(PKG_VERSION_MAJOR).$(PKG_VERSION_PATCH)
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/domoticz/domoticz/archive/$(PKG_VERSION)/$(PKG_SOURCE) PKG_SOURCE_URL:=https://github.com/domoticz/domoticz/archive/$(PKG_VERSION)/$(PKG_SOURCE)
@ -72,7 +72,7 @@ define Build/Prepare
buienradar_rain_example.pl \ buienradar_rain_example.pl \
_domoticz_main* \ _domoticz_main* \
download_update.sh \ download_update.sh \
dzVents/{.gitignore,documentation,examples} \ dzVents/{.gitignore,documentation,examples,generated_scripts} \
dzVents/runtime/{integration-tests,misc/smoothing.xlsx,tests} \ dzVents/runtime/{integration-tests,misc/smoothing.xlsx,tests} \
logrotate/ \ logrotate/ \
lua_parsers/example* \ lua_parsers/example* \

View File

@ -20,9 +20,9 @@ start_domoticz() {
[ -n "$loglevel" ] && procd_append_param command -loglevel "$loglevel" [ -n "$loglevel" ] && procd_append_param command -loglevel "$loglevel"
[ -n "$syslog" ] && procd_append_param command -syslog "$syslog" [ -n "$syslog" ] && procd_append_param command -syslog "$syslog"
[ -n "$userdata" ] && { [ -n "$userdata" ] && {
mkdir -p "$userdata" mkdir -p "${userdata}/generated_scripts"
chmod 0770 "$userdata" chmod -R 0770 "$userdata"
chown domoticz:domoticz "$userdata" chown -R domoticz:domoticz "$userdata"
procd_append_param command -userdata "$userdata" procd_append_param command -userdata "$userdata"
} }
[ -n "$sslcert" -a "${sslwww:-0}" -gt 0 ] && { [ -n "$sslcert" -a "${sslwww:-0}" -gt 0 ] && {

View File

@ -1,3 +1,27 @@
diff --git a/hardware/EvohomeScript.cpp b/hardware/EvohomeScript.cpp
index 5258fc55..0a44e97c 100644
--- a/hardware/EvohomeScript.cpp
+++ b/hardware/EvohomeScript.cpp
@@ -30,7 +30,7 @@
#include <string>
-extern std::string szUserDataFolder;
+extern std::string szScriptsFolder;
CEvohomeScript::CEvohomeScript(const int ID)
@@ -143,7 +143,7 @@ void CEvohomeScript::RunScript(const char *pdata, const unsigned char length)
std::string scriptname = OnAction.substr(9);
#if !defined WIN32
if (scriptname.find("/") != 0)
- scriptname = szUserDataFolder + "scripts/" + scriptname;
+ scriptname = szScriptsFolder + "scripts/" + scriptname;
#endif
std::string scriptparams="";
//Add parameters
diff --git a/hardware/OpenZWave.cpp b/hardware/OpenZWave.cpp
index 1f5c341c..24db61c9 100644
--- a/hardware/OpenZWave.cpp --- a/hardware/OpenZWave.cpp
+++ b/hardware/OpenZWave.cpp +++ b/hardware/OpenZWave.cpp
@@ -948,7 +948,7 @@ bool COpenZWave::OpenSerialConnector() @@ -948,7 +948,7 @@ bool COpenZWave::OpenSerialConnector()
@ -9,18 +33,31 @@
std::string UserPath = ConfigPath; std::string UserPath = ConfigPath;
if (szStartupFolder != szUserDataFolder) if (szStartupFolder != szUserDataFolder)
{ {
diff --git a/main/EventSystem.cpp b/main/EventSystem.cpp
index 4eff02fd..f2b17b97 100644
--- a/main/EventSystem.cpp --- a/main/EventSystem.cpp
+++ b/main/EventSystem.cpp +++ b/main/EventSystem.cpp
@@ -33,7 +33,7 @@ extern "C" { @@ -33,9 +33,11 @@ extern "C" {
#endif #endif
} }
-extern std::string szUserDataFolder;
+extern std::string szScriptsFolder; +extern std::string szScriptsFolder;
extern std::string szUserDataFolder;
extern http::server::CWebServerHelper m_webservers; extern http::server::CWebServerHelper m_webservers;
+static std::string dzv_Dir;
static std::string m_printprefix; static std::string m_printprefix;
@@ -149,7 +149,7 @@ void CEventSystem::StartEventSystem()
#ifdef ENABLE_PYTHON
@@ -115,7 +117,6 @@ static const _tJsonMap JsonMap[] =
{ NULL, NULL, tString }
};
-
CEventSystem::CEventSystem(void)
{
m_stoprequested = false;
@@ -149,7 +150,7 @@ void CEventSystem::StartEventSystem()
GetCurrentScenesGroups(); GetCurrentScenesGroups();
GetCurrentUserVariables(); GetCurrentUserVariables();
#ifdef ENABLE_PYTHON #ifdef ENABLE_PYTHON
@ -29,19 +66,22 @@
#endif #endif
m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CEventSystem::Do_Work, this))); m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CEventSystem::Do_Work, this)));
@@ -181,9 +181,9 @@ void CEventSystem::LoadEvents() @@ -179,11 +180,11 @@ void CEventSystem::SetEnabled(const bool bEnabled)
void CEventSystem::LoadEvents()
{ {
std::string dzv_Dir,s; - std::string dzv_Dir,s;
+ std::string s;
#ifdef WIN32 #ifdef WIN32
- dzv_Dir = szUserDataFolder + "scripts\\dzVents\\generated_scripts\\"; - dzv_Dir = szUserDataFolder + "scripts\\dzVents\\generated_scripts\\";
+ dzv_Dir = szScriptsFolder + "dzVents\\generated_scripts\\"; + dzv_Dir = szUserDataFolder + "generated_scripts\\";
#else #else
- dzv_Dir = szUserDataFolder + "scripts/dzVents/generated_scripts/"; - dzv_Dir = szUserDataFolder + "scripts/dzVents/generated_scripts/";
+ dzv_Dir = szScriptsFolder + "dzVents/generated_scripts/"; + dzv_Dir = szUserDataFolder + "generated_scripts/";
#endif #endif
boost::unique_lock<boost::shared_mutex> eventsMutexLock(m_eventsMutex); boost::unique_lock<boost::shared_mutex> eventsMutexLock(m_eventsMutex);
_log.Log(LOG_STATUS, "EventSystem: reset all events..."); _log.Log(LOG_STATUS, "EventSystem: reset all events...");
@@ -274,18 +274,18 @@ void CEventSystem::LoadEvents() @@ -274,18 +275,18 @@ void CEventSystem::LoadEvents()
void CEventSystem::Do_Work() void CEventSystem::Do_Work()
{ {
#ifdef WIN32 #ifdef WIN32
@ -66,7 +106,7 @@
#endif #endif
#endif #endif
m_stoprequested = false; m_stoprequested = false;
@@ -1426,9 +1426,9 @@ void CEventSystem::EvaluateEvent(const s @@ -1426,9 +1427,9 @@ void CEventSystem::EvaluateEvent(const std::string &reason, const uint64_t Devic
{ {
std::string dzv_scripts; std::string dzv_scripts;
#ifdef WIN32 #ifdef WIN32
@ -78,7 +118,7 @@
#endif #endif
DirectoryListing(FileEntries, dzv_scripts, false, true); DirectoryListing(FileEntries, dzv_scripts, false, true);
for (itt = FileEntries.begin(); itt != FileEntries.end(); ++itt) for (itt = FileEntries.begin(); itt != FileEntries.end(); ++itt)
@@ -2404,7 +2404,7 @@ bool CEventSystem::parseBlocklyActions(c @@ -2404,7 +2405,7 @@ bool CEventSystem::parseBlocklyActions(const std::string &Actions, const std::st
} }
#if !defined WIN32 #if !defined WIN32
if (sPath.find("/") != 0) if (sPath.find("/") != 0)
@ -87,7 +127,7 @@
#endif #endif
m_sql.AddTaskItem(_tTaskItem::ExecuteScript(0.2f, sPath, sParam)); m_sql.AddTaskItem(_tTaskItem::ExecuteScript(0.2f, sPath, sParam));
@@ -3508,11 +3508,11 @@ void CEventSystem::EvaluateLua(const std @@ -3508,13 +3509,16 @@ void CEventSystem::EvaluateLua(const std::string &reason, const std::string &fil
{ {
std::stringstream lua_DirT; std::stringstream lua_DirT;
@ -101,8 +141,13 @@
+ "dzVents/"; + "dzVents/";
#endif #endif
+ lua_pushstring(lua_state, "generated_script_path");
+ lua_pushstring(lua_state, dzv_Dir.c_str());
+ lua_rawset(lua_state, -3);
lua_pushstring(lua_state, "script_path"); lua_pushstring(lua_state, "script_path");
@@ -4695,9 +4695,9 @@ namespace http { lua_pushstring(lua_state, lua_DirT.str().c_str());
lua_rawset(lua_state, -3);
@@ -4695,9 +4699,9 @@ namespace http {
std::stringstream template_file; std::stringstream template_file;
#ifdef WIN32 #ifdef WIN32
@ -114,6 +159,33 @@
#endif #endif
std::ifstream file; std::ifstream file;
std::stringstream template_content; std::stringstream template_content;
diff --git a/main/EventsPythonModule.cpp b/main/EventsPythonModule.cpp
index f69e7219..2d97562e 100644
--- a/main/EventsPythonModule.cpp
+++ b/main/EventsPythonModule.cpp
@@ -108,7 +108,7 @@
int PythonEventsInitalized = 0;
- bool PythonEventsInitialize(std::string szUserDataFolder) {
+ bool PythonEventsInitialize(std::string szScriptsFolder) {
if (!Plugins::Py_LoadLibrary())
{
@@ -131,9 +131,9 @@
std::string ssPath;
#ifdef WIN32
- ssPath = szUserDataFolder + "scripts\\python\\;";
+ ssPath = szScriptsFolder + "python\\;";
#else
- ssPath = szUserDataFolder + "scripts/python/:";
+ ssPath = szScriptsFolder + "python/:";
#endif
std::wstring sPath = std::wstring(ssPath.begin(), ssPath.end());
diff --git a/main/LuaHandler.cpp b/main/LuaHandler.cpp
index 8fdcb278..c2ad98ff 100644
--- a/main/LuaHandler.cpp --- a/main/LuaHandler.cpp
+++ b/main/LuaHandler.cpp +++ b/main/LuaHandler.cpp
@@ -22,7 +22,7 @@ extern "C" { @@ -22,7 +22,7 @@ extern "C" {
@ -125,7 +197,7 @@
int CLuaHandler::l_domoticz_updateDevice(lua_State* lua_state) int CLuaHandler::l_domoticz_updateDevice(lua_State* lua_state)
{ {
@@ -155,9 +155,9 @@ bool CLuaHandler::executeLuaScript(const @@ -155,9 +155,9 @@ bool CLuaHandler::executeLuaScript(const std::string &script, const std::string
{ {
std::stringstream lua_DirT; std::stringstream lua_DirT;
#ifdef WIN32 #ifdef WIN32
@ -137,6 +209,8 @@
#endif #endif
std::string lua_Dir = lua_DirT.str(); std::string lua_Dir = lua_DirT.str();
diff --git a/main/SQLHelper.cpp b/main/SQLHelper.cpp
index 491aa5a2..d529243a 100644
--- a/main/SQLHelper.cpp --- a/main/SQLHelper.cpp
+++ b/main/SQLHelper.cpp +++ b/main/SQLHelper.cpp
@@ -633,6 +633,7 @@ const char *sqlCreateMobileDevices = @@ -633,6 +633,7 @@ const char *sqlCreateMobileDevices =
@ -147,7 +221,7 @@
extern std::string szUserDataFolder; extern std::string szUserDataFolder;
CSQLHelper::CSQLHelper(void) CSQLHelper::CSQLHelper(void)
@@ -3683,9 +3684,9 @@ uint64_t CSQLHelper::UpdateValueInt(cons @@ -3683,9 +3684,9 @@ uint64_t CSQLHelper::UpdateValueInt(const int HardwareID, const char* ID, const
//Execute possible script //Execute possible script
std::string scriptname; std::string scriptname;
#ifdef WIN32 #ifdef WIN32
@ -159,7 +233,7 @@
#endif #endif
if (file_exist(scriptname.c_str())) if (file_exist(scriptname.c_str()))
{ {
@@ -6641,7 +6642,7 @@ bool CSQLHelper::HandleOnOffAction(const @@ -6641,7 +6642,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
std::string scriptname = OnAction.substr(9); std::string scriptname = OnAction.substr(9);
#if !defined WIN32 #if !defined WIN32
if (scriptname.find("/") != 0) if (scriptname.find("/") != 0)
@ -168,7 +242,7 @@
#endif #endif
std::string scriptparams=""; std::string scriptparams="";
//Add parameters //Add parameters
@@ -6675,7 +6676,7 @@ bool CSQLHelper::HandleOnOffAction(const @@ -6675,7 +6676,7 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
std::string scriptname = OffAction.substr(9); std::string scriptname = OffAction.substr(9);
#if !defined WIN32 #if !defined WIN32
if (scriptname.find("/") != 0) if (scriptname.find("/") != 0)
@ -177,6 +251,8 @@
#endif #endif
std::string scriptparams = ""; std::string scriptparams = "";
int pindex = scriptname.find(' '); int pindex = scriptname.find(' ');
diff --git a/main/WebServer.cpp b/main/WebServer.cpp
index f8471791..d2cf10b2 100644
--- a/main/WebServer.cpp --- a/main/WebServer.cpp
+++ b/main/WebServer.cpp +++ b/main/WebServer.cpp
@@ -59,6 +59,7 @@ @@ -59,6 +59,7 @@
@ -199,6 +275,8 @@
#endif #endif
if (!file_exist(scriptname.c_str())) if (!file_exist(scriptname.c_str()))
return; return;
diff --git a/main/domoticz.cpp b/main/domoticz.cpp
index 5ef96f68..52599b14 100644
--- a/main/domoticz.cpp --- a/main/domoticz.cpp
+++ b/main/domoticz.cpp +++ b/main/domoticz.cpp
@@ -136,6 +136,7 @@ static const _facilities facilities[] = @@ -136,6 +136,7 @@ static const _facilities facilities[] =
@ -229,6 +307,8 @@
if (cmdLine.HasSwitch("-startupdelay")) if (cmdLine.HasSwitch("-startupdelay"))
{ {
if (cmdLine.GetArgumentCount("-startupdelay") != 1) if (cmdLine.GetArgumentCount("-startupdelay") != 1)
diff --git a/main/mainworker.cpp b/main/mainworker.cpp
index 803690e1..e89a783b 100644
--- a/main/mainworker.cpp --- a/main/mainworker.cpp
+++ b/main/mainworker.cpp +++ b/main/mainworker.cpp
@@ -159,6 +159,7 @@ @@ -159,6 +159,7 @@
@ -250,6 +330,8 @@
if (bIsBetaChannel) if (bIsBetaChannel)
strparm += " /beta"; strparm += " /beta";
diff --git a/notifications/NotificationHTTP.cpp b/notifications/NotificationHTTP.cpp
index decff3b4..632e4e66 100644
--- a/notifications/NotificationHTTP.cpp --- a/notifications/NotificationHTTP.cpp
+++ b/notifications/NotificationHTTP.cpp +++ b/notifications/NotificationHTTP.cpp
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
@ -261,7 +343,7 @@
CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"), OPTIONS_NONE) CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"), OPTIONS_NONE)
{ {
@@ -105,7 +105,7 @@ bool CNotificationHTTP::SendMessageImple @@ -105,7 +105,7 @@ bool CNotificationHTTP::SendMessageImplementation(
std::string scriptparams = ""; std::string scriptparams = "";
#if !defined WIN32 #if !defined WIN32
if (scriptname.find("/") != 0) if (scriptname.find("/") != 0)
@ -270,6 +352,8 @@
#endif #endif
//Add parameters //Add parameters
uPos = scriptname.find(" "); uPos = scriptname.find(" ");
diff --git a/push/GooglePubSubPush.cpp b/push/GooglePubSubPush.cpp
index 359a7d7c..46e489f6 100644
--- a/push/GooglePubSubPush.cpp --- a/push/GooglePubSubPush.cpp
+++ b/push/GooglePubSubPush.cpp +++ b/push/GooglePubSubPush.cpp
@@ -22,7 +22,7 @@ extern "C" { @@ -22,7 +22,7 @@ extern "C" {
@ -281,7 +365,7 @@
// this should be filled in by the preprocessor // this should be filled in by the preprocessor
extern const char * Python_exe; extern const char * Python_exe;
@@ -231,11 +231,11 @@ void CGooglePubSubPush::DoGooglePubSubPu @@ -231,11 +231,11 @@ void CGooglePubSubPush::DoGooglePubSubPush()
#ifdef ENABLE_PYTHON_DECAP #ifdef ENABLE_PYTHON_DECAP
#ifdef WIN32 #ifdef WIN32
@ -297,46 +381,27 @@
#endif #endif
wchar_t * argv[1]; wchar_t * argv[1];
--- a/hardware/EvohomeScript.cpp diff --git a/scripts/dzVents/runtime/dzVents.lua b/scripts/dzVents/runtime/dzVents.lua
+++ b/hardware/EvohomeScript.cpp index d0dfa869..8370d6a9 100644
@@ -30,7 +30,7 @@ --- a/scripts/dzVents/runtime/dzVents.lua
+++ b/scripts/dzVents/runtime/dzVents.lua
@@ -1,8 +1,9 @@
local currentPath = globalvariables['script_path']
+local generatedScriptPath = globalvariables['generated_script_path']
local triggerReason = globalvariables['script_reason']
#include <string> _G.scriptsFolderPath = currentPath .. 'scripts' -- global
-_G.generatedScriptsFolderPath = currentPath .. 'generated_scripts' -- global
+_G.generatedScriptsFolderPath = generatedScriptPath -- global
_G.dataFolderPath = currentPath .. 'data' -- global
-extern std::string szUserDataFolder; package.path = package.path .. ';' .. currentPath .. '?.lua'
+extern std::string szScriptsFolder; @@ -10,7 +11,7 @@ package.path = package.path .. ';' .. currentPath .. 'runtime/?.lua'
package.path = package.path .. ';' .. currentPath .. 'runtime/device-adapters/?.lua'
package.path = package.path .. ';' .. currentPath .. 'dzVents/?.lua'
package.path = package.path .. ';' .. currentPath .. 'scripts/?.lua'
-package.path = package.path .. ';' .. currentPath .. 'generated_scripts/?.lua'
+package.path = package.path .. ';' .. generatedScriptPath .. '?.lua'
package.path = package.path .. ';' .. currentPath .. 'data/?.lua'
local EventHelpers = require('EventHelpers')
CEvohomeScript::CEvohomeScript(const int ID)
@@ -143,7 +143,7 @@ void CEvohomeScript::RunScript(const cha
std::string scriptname = OnAction.substr(9);
#if !defined WIN32
if (scriptname.find("/") != 0)
- scriptname = szUserDataFolder + "scripts/" + scriptname;
+ scriptname = szScriptsFolder + "scripts/" + scriptname;
#endif
std::string scriptparams="";
//Add parameters
--- a/main/EventsPythonModule.cpp
+++ b/main/EventsPythonModule.cpp
@@ -108,7 +108,7 @@
int PythonEventsInitalized = 0;
- bool PythonEventsInitialize(std::string szUserDataFolder) {
+ bool PythonEventsInitialize(std::string szScriptsFolder) {
if (!Plugins::Py_LoadLibrary())
{
@@ -131,9 +131,9 @@
std::string ssPath;
#ifdef WIN32
- ssPath = szUserDataFolder + "scripts\\python\\;";
+ ssPath = szScriptsFolder + "python\\;";
#else
- ssPath = szUserDataFolder + "scripts/python/:";
+ ssPath = szScriptsFolder + "python/:";
#endif
std::wstring sPath = std::wstring(ssPath.begin(), ssPath.end());