Adds support to the TIME* variables

This commit is contained in:
Felipe Zimmerle
2015-07-22 01:06:08 -03:00
parent ad442fb201
commit 6f7d3fa67a
30 changed files with 1488 additions and 2 deletions

59
src/variables/time.cc Normal file
View File

@@ -0,0 +1,59 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
Time::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%H:%M:%S", &timeinfo);
pair = std::make_pair(std::string("TIME"),
std::string(tstr));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

44
src/variables/time.h Normal file
View File

@@ -0,0 +1,44 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_H_
#define SRC_VARIABLES_TIME_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class Time : public Variable {
public:
explicit Time(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_H_

59
src/variables/time_day.cc Normal file
View File

@@ -0,0 +1,59 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_day.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeDay::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%d", &timeinfo);
pair = std::make_pair(std::string("TIME_DAY"),
std::string(tstr));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_day.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_DAY_H_
#define SRC_VARIABLES_TIME_DAY_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeDay : public Variable {
public:
explicit TimeDay(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_DAY_H_

View File

@@ -0,0 +1,50 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_epoch.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeEpoch::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
pair = std::make_pair(std::string("TIME_EPOCH"),
std::to_string(std::time(nullptr)));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_EPOCH_H_
#define SRC_VARIABLES_TIME_EPOCH_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeEpoch : public Variable {
public:
explicit TimeEpoch(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_EPOCH_H_

View File

@@ -0,0 +1,59 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_hour.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeHour::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%H", &timeinfo);
pair = std::make_pair(std::string("TIME_HOUR"),
std::string(tstr));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_hour.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_HOUR_H_
#define SRC_VARIABLES_TIME_HOUR_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeHour : public Variable {
public:
explicit TimeHour(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_HOUR_H_

59
src/variables/time_min.cc Normal file
View File

@@ -0,0 +1,59 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_min.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeMin::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%M", &timeinfo);
pair = std::make_pair(std::string("TIME_MIN"),
std::string(tstr));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_min.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_MIN_H_
#define SRC_VARIABLES_TIME_MIN_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeMin : public Variable {
public:
explicit TimeMin(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_MIN_H_

61
src/variables/time_mon.cc Normal file
View File

@@ -0,0 +1,61 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_mon.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeMon::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%m", &timeinfo);
int a = atoi(tstr);
a--;
pair = std::make_pair(std::string("TIME_MON"),
std::to_string(a));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_mon.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_MON_H_
#define SRC_VARIABLES_TIME_MON_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeMon : public Variable {
public:
explicit TimeMon(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_MON_H_

59
src/variables/time_sec.cc Normal file
View File

@@ -0,0 +1,59 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_sec.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeSec::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%S", &timeinfo);
pair = std::make_pair(std::string("TIME_SEC"),
std::string(tstr));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_sec.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_SEC_H_
#define SRC_VARIABLES_TIME_SEC_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeSec : public Variable {
public:
explicit TimeSec(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_SEC_H_

View File

@@ -0,0 +1,61 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_wday.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeWDay::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%u", &timeinfo);
int a = atoi(tstr);
a--;
pair = std::make_pair(std::string("TIME_WDAY"),
std::to_string(a));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_wday.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_WDAY_H_
#define SRC_VARIABLES_TIME_WDAY_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeWDay : public Variable {
public:
explicit TimeWDay(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_WDAY_H_

View File

@@ -0,0 +1,59 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "variables/time_year.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace Variables {
std::list<std::pair<std::string, std::string>>
TimeYear::evaluate(Assay *assay) {
std::list<std::pair<std::string, std::string>> resl;
std::pair<std::string, std::string> pair;
char tstr[200];
struct tm timeinfo;
time_t timer;
time(&timer);
memset(tstr, '\0', 200);
localtime_r(&timer, &timeinfo);
strftime(tstr, 200, "%Y", &timeinfo);
pair = std::make_pair(std::string("TIME_YEAR"),
std::string(tstr));
resl.push_back(pair);
return resl;
}
} // namespace Variables
} // namespace ModSecurity

43
src/variables/time_year.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <vector>
#include <string>
#include <list>
#include <utility>
#ifndef SRC_VARIABLES_TIME_YEAR_H_
#define SRC_VARIABLES_TIME_YEAR_H_
#include "src/variable.h"
namespace ModSecurity {
class Assay;
namespace Variables {
class TimeYear : public Variable {
public:
explicit TimeYear(std::string _name)
: Variable(_name) { }
std::list<std::pair<std::string, std::string>>
evaluate(Assay *assay) override;
};
} // namespace Variables
} // namespace ModSecurity
#endif // SRC_VARIABLES_TIME_YEAR_H_