Added config_file_encoding token to change input module_exec
Change name to module_native_encoding to change output module_exec
This commit is contained in:
parent
a85ed6e550
commit
772c378424
|
@ -42,6 +42,7 @@ Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec)
|
||||||
this->proc = 0;
|
this->proc = 0;
|
||||||
this->setKind (module_exec_str);
|
this->setKind (module_exec_str);
|
||||||
this->native_encoding = -1;
|
this->native_encoding = -1;
|
||||||
|
this->config_encoding = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,11 +77,13 @@ Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec, string nativ
|
||||||
pandoraDebug("module_native %s in %s module is not a properly encoding",
|
pandoraDebug("module_native %s in %s module is not a properly encoding",
|
||||||
native.c_str (), name.c_str ());
|
native.c_str (), name.c_str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this->output_encoding = "";
|
this->output_encoding = "";
|
||||||
this->native_encoding = -1;
|
this->native_encoding = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getConfigFileEncoding();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -148,8 +151,10 @@ Pandora_Module_Exec::run () {
|
||||||
to find the GNU W32 tools */
|
to find the GNU W32 tools */
|
||||||
working_dir = getPandoraInstallDir () + "util\\";
|
working_dir = getPandoraInstallDir () + "util\\";
|
||||||
|
|
||||||
/*always change input from UTF-8 to ANSI*/
|
/*change input encoding if config_file_encoding token is present*/
|
||||||
changeInputEncoding();
|
if (this->config_encoding != -1){
|
||||||
|
changeInputEncoding();
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the child process. */
|
/* Create the child process. */
|
||||||
if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL,
|
if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL,
|
||||||
|
@ -406,7 +411,38 @@ UINT Pandora_Module_Exec::getNumberEncoding (string encoding){
|
||||||
|
|
||||||
void Pandora_Module_Exec::getOutputEncoding(){
|
void Pandora_Module_Exec::getOutputEncoding(){
|
||||||
|
|
||||||
this->output_encoding = "ISO-8859-1"; //initialize with default encoding
|
string buffer, filename;
|
||||||
|
int pos;
|
||||||
|
filename = Pandora::getPandoraInstallDir ();
|
||||||
|
filename += "pandora_agent.conf";
|
||||||
|
|
||||||
|
ifstream file;
|
||||||
|
file.open (filename.c_str ());
|
||||||
|
this->output_encoding = "ISO-8859-1"; //by default
|
||||||
|
bool token_found = false;
|
||||||
|
|
||||||
|
while (!file.eof () && !token_found) {
|
||||||
|
/* Set the value from each line */
|
||||||
|
getline (file, buffer);
|
||||||
|
|
||||||
|
/* Ignore blank or commented lines */
|
||||||
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0' && buffer[0] != 'm') {
|
||||||
|
/*Check if is the encoding line*/
|
||||||
|
pos = buffer.find("encoding");
|
||||||
|
if (pos != string::npos){
|
||||||
|
this->output_encoding = "";
|
||||||
|
this->output_encoding = buffer.substr(pos+9);
|
||||||
|
token_found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pandora_Module_Exec::getConfigFileEncoding(){
|
||||||
|
|
||||||
|
string config_encoding_string;
|
||||||
|
config_encoding_string = "";
|
||||||
string buffer, filename;
|
string buffer, filename;
|
||||||
int pos;
|
int pos;
|
||||||
filename = Pandora::getPandoraInstallDir ();
|
filename = Pandora::getPandoraInstallDir ();
|
||||||
|
@ -423,23 +459,27 @@ void Pandora_Module_Exec::getOutputEncoding(){
|
||||||
/* Ignore blank or commented lines */
|
/* Ignore blank or commented lines */
|
||||||
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
||||||
/*Check if is the encoding line*/
|
/*Check if is the encoding line*/
|
||||||
pos = buffer.find("encoding");
|
pos = buffer.find("config_file_encoding");
|
||||||
if (pos != string::npos){
|
if (pos != string::npos){
|
||||||
this->output_encoding = "";
|
config_encoding_string = buffer.substr (pos+21);
|
||||||
this->output_encoding = buffer.substr(pos+9);
|
|
||||||
token_found = true;
|
token_found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (token_found) {
|
||||||
|
this->config_encoding = getNumberEncoding (config_encoding_string);
|
||||||
|
} else {
|
||||||
|
this->config_encoding = -1;
|
||||||
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pandora_Module_Exec::changeInputEncoding(){
|
void Pandora_Module_Exec::changeInputEncoding(){
|
||||||
|
|
||||||
int size_wchar = MultiByteToWideChar( CP_UTF8 , 0 , this->module_exec.c_str () , -1, NULL , 0 );
|
int size_wchar = MultiByteToWideChar( this->config_encoding , 0 , this->module_exec.c_str () , -1, NULL , 0 );
|
||||||
wchar_t* wstr = new wchar_t[size_wchar];
|
wchar_t* wstr = new wchar_t[size_wchar];
|
||||||
if (size_wchar != 0){
|
if (size_wchar != 0){
|
||||||
MultiByteToWideChar( CP_UTF8 , 0 , this->module_exec.c_str () , -1, wstr , size_wchar );
|
MultiByteToWideChar( this->config_encoding , 0 , this->module_exec.c_str () , -1, wstr , size_wchar );
|
||||||
char buf[BUFSIZE + 1];
|
char buf[BUFSIZE + 1];
|
||||||
wcstombs(buf, wstr, size_wchar);
|
wcstombs(buf, wstr, size_wchar);
|
||||||
buf[size_wchar] = '\0';
|
buf[size_wchar] = '\0';
|
||||||
|
|
|
@ -33,13 +33,15 @@ namespace Pandora_Modules {
|
||||||
*/
|
*/
|
||||||
class Pandora_Module_Exec : public Pandora_Module {
|
class Pandora_Module_Exec : public Pandora_Module {
|
||||||
private:
|
private:
|
||||||
string module_exec;
|
string module_exec;
|
||||||
UINT native_encoding;
|
UINT native_encoding;
|
||||||
string output_encoding;
|
string output_encoding;
|
||||||
UINT getNumberEncoding(string encoding);
|
UINT getNumberEncoding(string encoding);
|
||||||
|
UINT config_encoding;
|
||||||
void getOutputEncoding();
|
void getOutputEncoding();
|
||||||
void changeInputEncoding();
|
void changeInputEncoding();
|
||||||
void changeOutputEncoding(string * string_change);
|
void changeOutputEncoding(string * string_change);
|
||||||
|
void getConfigFileEncoding();
|
||||||
public:
|
public:
|
||||||
unsigned char proc;
|
unsigned char proc;
|
||||||
Pandora_Module_Exec (string name, string exec);
|
Pandora_Module_Exec (string name, string exec);
|
||||||
|
|
|
@ -118,7 +118,7 @@ using namespace Pandora_Strutils;
|
||||||
#define TOKEN_QUIET ("module_quiet ")
|
#define TOKEN_QUIET ("module_quiet ")
|
||||||
#define TOKEN_MODULE_FF_INTERVAL ("module_ff_interval ")
|
#define TOKEN_MODULE_FF_INTERVAL ("module_ff_interval ")
|
||||||
#define TOKEN_MACRO ("module_macro")
|
#define TOKEN_MACRO ("module_macro")
|
||||||
#define TOKEN_NATIVE ("module_native")
|
#define TOKEN_NATIVE_ENCODING ("module_native_encoding")
|
||||||
|
|
||||||
string
|
string
|
||||||
parseLine (string line, string token) {
|
parseLine (string line, string token) {
|
||||||
|
@ -171,7 +171,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
string module_unit, module_group, module_custom_id, module_str_warning, module_str_critical;
|
string module_unit, module_group, module_custom_id, module_str_warning, module_str_critical;
|
||||||
string module_critical_instructions, module_warning_instructions, module_unknown_instructions, module_tags;
|
string module_critical_instructions, module_warning_instructions, module_unknown_instructions, module_tags;
|
||||||
string module_critical_inverse, module_warning_inverse, module_quiet, module_ff_interval;
|
string module_critical_inverse, module_warning_inverse, module_quiet, module_ff_interval;
|
||||||
string module_native;
|
string module_native_encoding;
|
||||||
string macro;
|
string macro;
|
||||||
Pandora_Module *module;
|
Pandora_Module *module;
|
||||||
bool numeric;
|
bool numeric;
|
||||||
|
@ -249,7 +249,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
module_warning_inverse = "";
|
module_warning_inverse = "";
|
||||||
module_quiet = "";
|
module_quiet = "";
|
||||||
module_ff_interval = "";
|
module_ff_interval = "";
|
||||||
module_native = "";
|
module_native_encoding = "";
|
||||||
macro = "";
|
macro = "";
|
||||||
|
|
||||||
stringtok (tokens, definition, "\n");
|
stringtok (tokens, definition, "\n");
|
||||||
|
@ -493,8 +493,8 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
module_quiet = parseLine (line, TOKEN_QUIET);
|
module_quiet = parseLine (line, TOKEN_QUIET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module_native == "") {
|
if (module_native_encoding == "") {
|
||||||
module_native = parseLine (line, TOKEN_NATIVE);
|
module_native_encoding = parseLine (line, TOKEN_NATIVE_ENCODING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module_ff_interval == "") {
|
if (module_ff_interval == "") {
|
||||||
|
@ -1056,10 +1056,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module_native != "") {
|
if (module_native_encoding != "") {
|
||||||
pos_macro = module_native.find(macro_name);
|
pos_macro = module_native_encoding.find(macro_name);
|
||||||
if (pos_macro != string::npos){
|
if (pos_macro != string::npos){
|
||||||
module_native.replace(pos_macro, macro_name.size(), macro_value);
|
module_native_encoding.replace(pos_macro, macro_name.size(), macro_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1076,7 +1076,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
||||||
/* Create module objects */
|
/* Create module objects */
|
||||||
if (module_exec != "") {
|
if (module_exec != "") {
|
||||||
module = new Pandora_Module_Exec (module_name,
|
module = new Pandora_Module_Exec (module_name,
|
||||||
module_exec, module_native);
|
module_exec, module_native_encoding);
|
||||||
if (module_timeout != "") {
|
if (module_timeout != "") {
|
||||||
module->setTimeout (atoi (module_timeout.c_str ()));
|
module->setTimeout (atoi (module_timeout.c_str ()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue