@@ -1879,27 +1879,54 @@ namespace http {
1879
1879
if (session.rights != 2)
1880
1880
{
1881
1881
session.reply_status = reply::forbidden;
1882
+ _log.Log(LOG_ERROR, "User: %s tried to add a uservariable!", session.username.c_str());
1882
1883
return; //Only admin user allowed
1883
1884
}
1884
1885
std::string variablename = request::findValue(&req, "vname");
1885
1886
std::string variablevalue = request::findValue(&req, "vvalue");
1886
1887
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
+
1887
1912
if (
1888
1913
(variablename.empty()) ||
1889
1914
(variabletype.empty()) ||
1915
+ ((variabletype != "0") && (variabletype != "1") && (variabletype != "2") && (variabletype != "3") && (variabletype != "4")) ||
1890
1916
((variablevalue.empty()) && (variabletype != "2"))
1891
1917
)
1918
+ {
1919
+ root["message"] = "Invalid variabletype " + variabletype;
1892
1920
return;
1893
-
1894
- root["title"] = "AddUserVariable";
1921
+ }
1895
1922
1896
1923
std::string errorMessage;
1897
1924
if (!m_sql.AddUserVariable(variablename, (const _eUsrVariableType)atoi(variabletype.c_str()), variablevalue, errorMessage))
1898
1925
{
1899
- root["status"] = "ERR";
1900
1926
root["message"] = errorMessage;
1901
1927
}
1902
- else {
1928
+ else
1929
+ {
1903
1930
root["status"] = "OK";
1904
1931
}
1905
1932
}
@@ -1908,6 +1935,7 @@ namespace http {
1908
1935
{
1909
1936
if (session.rights != 2)
1910
1937
{
1938
+ _log.Log(LOG_ERROR, "User: %s tried to delete a uservariable!", session.username.c_str());
1911
1939
session.reply_status = reply::forbidden;
1912
1940
return; //Only admin user allowed
1913
1941
}
@@ -1924,47 +1952,78 @@ namespace http {
1924
1952
{
1925
1953
if (session.rights != 2)
1926
1954
{
1955
+ _log.Log(LOG_ERROR, "User: %s tried to update a uservariable!", session.username.c_str());
1927
1956
session.reply_status = reply::forbidden;
1928
1957
return; //Only admin user allowed
1929
1958
}
1930
-
1959
+
1931
1960
std::string idx = request::findValue(&req, "idx");
1932
1961
std::string variablename = request::findValue(&req, "vname");
1933
1962
std::string variablevalue = request::findValue(&req, "vvalue");
1934
1963
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
+
1936
1988
if (
1937
1989
(variablename.empty()) ||
1938
1990
(variabletype.empty()) ||
1991
+ ((variabletype != "0") && (variabletype != "1") && (variabletype != "2") && (variabletype != "3") && (variabletype != "4")) ||
1939
1992
((variablevalue.empty()) && (variabletype != "2"))
1940
1993
)
1994
+ {
1995
+ root["message"] = "Invalid variabletype " + variabletype;
1941
1996
return;
1997
+ }
1942
1998
1943
1999
std::vector<std::vector<std::string> > result;
1944
2000
if (idx.empty())
1945
2001
{
1946
2002
result = m_sql.safe_query("SELECT ID FROM UserVariables WHERE Name='%q'", variablename.c_str());
1947
2003
if (result.empty())
2004
+ {
2005
+ root["message"] = "Uservariable " + variablename + " does not exist";
1948
2006
return;
2007
+ }
1949
2008
idx = result[0][0];
1950
2009
}
1951
2010
1952
2011
result = m_sql.safe_query("SELECT Name, ValueType FROM UserVariables WHERE ID='%q'", idx.c_str());
1953
2012
if (result.empty())
2013
+ {
2014
+ root["message"] = "Uservariable " + variablename + " does not exist";
1954
2015
return;
2016
+ }
1955
2017
1956
2018
bool bTypeNameChanged = false;
1957
2019
if (variablename != result[0][0])
1958
2020
bTypeNameChanged = true; //new name
1959
2021
else if (variabletype != result[0][1])
1960
2022
bTypeNameChanged = true; //new type
1961
2023
1962
- root["title"] = "UpdateUserVariable";
1963
-
1964
2024
std::string errorMessage;
1965
2025
if (!m_sql.UpdateUserVariable(idx, variablename, (const _eUsrVariableType)atoi(variabletype.c_str()), variablevalue, !bTypeNameChanged, errorMessage))
1966
2026
{
1967
- root["status"] = "ERR";
1968
2027
root["message"] = errorMessage;
1969
2028
}
1970
2029
else {
0 commit comments