Skip to content

Commit c0edefe

Browse files
committed
Merge branch 'development' of github.com:domoticz/domoticz into development
2 parents b9a44f1 + 095fdb2 commit c0edefe

File tree

4 files changed

+79
-12
lines changed

4 files changed

+79
-12
lines changed

History.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version 4.xxxxx (xxx 2019)
1212
- Fixed: GUI, OpenZWave Abort Include/Exclude button
1313
- Fixed: YouLess, possible buffer overflow (#3261)
1414
- Fixed: notification, Telegram error when odd number of underscores in text
15+
- Fixed: API, allow variabletype to be entered as text or integer in adduservariable and updateuservariable (#3320)
1516
- Updated: OpenZWave version 1.6
1617
- Updated: dzVents (version 2.4.23, See dzVents/documentation/history.md)
1718

main/WebServer.cpp

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,27 +1879,54 @@ namespace http {
18791879
if (session.rights != 2)
18801880
{
18811881
session.reply_status = reply::forbidden;
1882+
_log.Log(LOG_ERROR, "User: %s tried to add a uservariable!", session.username.c_str());
18821883
return; //Only admin user allowed
18831884
}
18841885
std::string variablename = request::findValue(&req, "vname");
18851886
std::string variablevalue = request::findValue(&req, "vvalue");
18861887
std::string variabletype = request::findValue(&req, "vtype");
1888+
1889+
root["title"] = "AddUserVariable";
1890+
root["status"] = "ERR";
1891+
1892+
if (!std::isdigit(variabletype[0]))
1893+
{
1894+
stdlower(variabletype);
1895+
if (variabletype == "integer")
1896+
variabletype = "0";
1897+
else if (variabletype == "float")
1898+
variabletype = "1";
1899+
else if (variabletype == "string")
1900+
variabletype = "2";
1901+
else if (variabletype == "date")
1902+
variabletype = "3";
1903+
else if (variabletype == "time")
1904+
variabletype = "4";
1905+
else
1906+
{
1907+
root["message"] = "Invalid variabletype " + variabletype;
1908+
return;
1909+
}
1910+
}
1911+
18871912
if (
18881913
(variablename.empty()) ||
18891914
(variabletype.empty()) ||
1915+
((variabletype != "0") && (variabletype != "1") && (variabletype != "2") && (variabletype != "3") && (variabletype != "4")) ||
18901916
((variablevalue.empty()) && (variabletype != "2"))
18911917
)
1918+
{
1919+
root["message"] = "Invalid variabletype " + variabletype;
18921920
return;
1893-
1894-
root["title"] = "AddUserVariable";
1921+
}
18951922

18961923
std::string errorMessage;
18971924
if (!m_sql.AddUserVariable(variablename, (const _eUsrVariableType)atoi(variabletype.c_str()), variablevalue, errorMessage))
18981925
{
1899-
root["status"] = "ERR";
19001926
root["message"] = errorMessage;
19011927
}
1902-
else {
1928+
else
1929+
{
19031930
root["status"] = "OK";
19041931
}
19051932
}
@@ -1908,6 +1935,7 @@ namespace http {
19081935
{
19091936
if (session.rights != 2)
19101937
{
1938+
_log.Log(LOG_ERROR, "User: %s tried to delete a uservariable!", session.username.c_str());
19111939
session.reply_status = reply::forbidden;
19121940
return; //Only admin user allowed
19131941
}
@@ -1924,47 +1952,78 @@ namespace http {
19241952
{
19251953
if (session.rights != 2)
19261954
{
1955+
_log.Log(LOG_ERROR, "User: %s tried to update a uservariable!", session.username.c_str());
19271956
session.reply_status = reply::forbidden;
19281957
return; //Only admin user allowed
19291958
}
1930-
1959+
19311960
std::string idx = request::findValue(&req, "idx");
19321961
std::string variablename = request::findValue(&req, "vname");
19331962
std::string variablevalue = request::findValue(&req, "vvalue");
19341963
std::string variabletype = request::findValue(&req, "vtype");
1935-
1964+
1965+
root["title"] = "UpdateUserVariable";
1966+
root["status"] = "ERR";
1967+
1968+
if (!std::isdigit(variabletype[0]))
1969+
{
1970+
stdlower(variabletype);
1971+
if (variabletype == "integer")
1972+
variabletype = "0";
1973+
else if (variabletype == "float")
1974+
variabletype = "1";
1975+
else if (variabletype == "string")
1976+
variabletype = "2";
1977+
else if (variabletype == "date")
1978+
variabletype = "3";
1979+
else if (variabletype == "time")
1980+
variabletype = "4";
1981+
else
1982+
{
1983+
root["message"] = "Invalid variabletype " + variabletype;
1984+
return;
1985+
}
1986+
}
1987+
19361988
if (
19371989
(variablename.empty()) ||
19381990
(variabletype.empty()) ||
1991+
((variabletype != "0") && (variabletype != "1") && (variabletype != "2") && (variabletype != "3") && (variabletype != "4")) ||
19391992
((variablevalue.empty()) && (variabletype != "2"))
19401993
)
1994+
{
1995+
root["message"] = "Invalid variabletype " + variabletype;
19411996
return;
1997+
}
19421998

19431999
std::vector<std::vector<std::string> > result;
19442000
if (idx.empty())
19452001
{
19462002
result = m_sql.safe_query("SELECT ID FROM UserVariables WHERE Name='%q'", variablename.c_str());
19472003
if (result.empty())
2004+
{
2005+
root["message"] = "Uservariable " + variablename + " does not exist";
19482006
return;
2007+
}
19492008
idx = result[0][0];
19502009
}
19512010

19522011
result = m_sql.safe_query("SELECT Name, ValueType FROM UserVariables WHERE ID='%q'", idx.c_str());
19532012
if (result.empty())
2013+
{
2014+
root["message"] = "Uservariable " + variablename + " does not exist";
19542015
return;
2016+
}
19552017

19562018
bool bTypeNameChanged = false;
19572019
if (variablename != result[0][0])
19582020
bTypeNameChanged = true; //new name
19592021
else if (variabletype != result[0][1])
19602022
bTypeNameChanged = true; //new type
19612023

1962-
root["title"] = "UpdateUserVariable";
1963-
19642024
std::string errorMessage;
19652025
if (!m_sql.UpdateUserVariable(idx, variablename, (const _eUsrVariableType)atoi(variabletype.c_str()), variablevalue, !bTypeNameChanged, errorMessage))
19662026
{
1967-
root["status"] = "ERR";
19682027
root["message"] = errorMessage;
19692028
}
19702029
else {

webserver/cWebem.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,11 @@ namespace http {
996996
return m_settings.listening_port;
997997
}
998998

999+
const std::string cWebem::GetWebRoot()
1000+
{
1001+
return m_webRoot;
1002+
}
1003+
9991004
WebEmSession * cWebem::GetSession(const std::string & ssid)
10001005
{
10011006
std::unique_lock<std::mutex> lock(m_sessionsMutex);
@@ -2024,11 +2029,12 @@ namespace http {
20242029
// do normal handling
20252030
try
20262031
{
2027-
if (requestCopy.uri.find("/images/") == 0)
2032+
std::string uri = myWebem->ExtractRequestPath(requestCopy.uri);
2033+
if (uri.find("/images/") == 0)
20282034
{
2029-
std::string theme_images_path = myWebem->m_actTheme + requestCopy.uri;
2035+
std::string theme_images_path = myWebem->m_actTheme + uri;
20302036
if (file_exist((doc_root_ + theme_images_path).c_str()))
2031-
requestCopy.uri = theme_images_path;
2037+
requestCopy.uri = myWebem->GetWebRoot() + theme_images_path;
20322038
}
20332039

20342040
request_handler::handle_request(requestCopy, rep, mInfo);

webserver/cWebem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ namespace http {
215215

216216
std::string m_zippassword;
217217
const std::string GetPort();
218+
const std::string GetWebRoot();
218219
WebEmSession * GetSession(const std::string & ssid);
219220
void AddSession(const WebEmSession & session);
220221
void RemoveSession(const WebEmSession & session);

0 commit comments

Comments
 (0)