2011-06-07 Vanessa Gil <vanessa.gil@artica.es>

* win32/pandora_agent_conf.cc
	  win32/pandora_agent_conf.h
	  win32/modules/pandora_module_list.cc
	  win32/modules/pandora_module_list.h: Allow the windows agent to include additional configuration files.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4419 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
vgilc 2011-06-08 14:12:57 +00:00
parent 39828a68c4
commit d0bd876295
5 changed files with 147 additions and 5 deletions

View File

@ -1,3 +1,10 @@
2011-06-07 Vanessa Gil <vanessa.gil@artica.es>
* win32/pandora_agent_conf.cc
win32/pandora_agent_conf.h
win32/modules/pandora_module_list.cc
win32/modules/pandora_module_list.h: Allow the windows agent to include additional configuration files.
2011-06-01 Vanessa Gil <vanessa.gil@artica.es>
* unix/pandora_agent: Allow the agent to include additional configuration files.

View File

@ -40,6 +40,58 @@
using namespace std;
/**
* Additional configuration file.
*/
void
Pandora_Modules::Pandora_Module_List::parseModuleConf (string path_file, list<Pandora_Module *> *modules) {
ifstream file_conf (path_file.c_str ());
string buffer;
unsigned int pos;
if (!file_conf.is_open ()) {
return;
}
/* Read and set the file */
while (!file_conf.eof ()) {
/* Set the value from each line */
getline (file_conf, buffer);
/* Ignore blank or commented lines */
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
/* Module */
pos = buffer.find ("module_begin");
if (pos != string::npos) {
string str_module = buffer + "\n";
bool module_end = false;
while (!module_end) {
if (file_conf.eof ()) {
break;
}
getline (file_conf, buffer);
pos = buffer.find ("module_end");
module_end = (pos != string::npos);
str_module += buffer + "\n";
}
this->parseModuleDefinition (str_module);
continue;
}
/* Plugin */
pos = buffer.find ("module_plugin");
if (pos != string::npos) {
this->parseModuleDefinition (buffer);
continue;
}
}
}
file_conf.close ();
return;
}
/**
* Read and set a key-value set from a file.
*
@ -66,6 +118,23 @@ Pandora_Modules::Pandora_Module_List::Pandora_Module_List (string filename) {
/* Ignore blank or commented lines */
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
/*Check if is a include*/
pos = buffer.find("include");
if (pos != string::npos){
string path_file;
unsigned pos_c;
path_file = buffer.substr(pos+8);
pos_c = path_file.find("\"");
/* Remove " */
while (pos_c != string::npos){
path_file.replace(pos_c, 1, "");
pos_c = path_file.find("\"",pos_c+1);
}
parseModuleConf(path_file, modules);
}
/* Module */
pos = buffer.find ("module_begin");

View File

@ -40,17 +40,18 @@ namespace Pandora_Modules {
private:
list<Pandora_Module *> *modules;
list<Pandora_Module *>::iterator *current;
void parseModuleConf (string path_file, list<Pandora_Module *> *modules);
void parseModuleDefinition (string definition);
public:
Pandora_Module_List (string filename);
Pandora_Module_List ();
Pandora_Module_List (string filename);
Pandora_Module_List ();
~Pandora_Module_List ();
Pandora_Module * getCurrentValue ();
/* Add a module to the list */
void addModule (Pandora_Module *module);
void addModule (Pandora_Module *module);
/* Move to the first element of the list */
void goFirst ();

View File

@ -53,6 +53,54 @@ Pandora::Pandora_Agent_Conf::getInstance () {
return conf;
}
/**
* Additional configuration file.
*/
void
Pandora::Pandora_Agent_Conf::parseFile(string path_file, Collection *aux){
ifstream file_conf (path_file.c_str ());
string buffer;
unsigned int pos;
if (!file_conf.is_open ()) {
return;
}
/* Read and set the file */
while (!file_conf.eof ()) {
/* Set the value from each line */
getline (file_conf, buffer);
/* Ignore blank or commented lines */
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
/*Check if is a collection*/
pos = buffer.find("file_collection");
if(pos != string::npos) {
string collection_name, trimmed_str;
/*Add collection to collection_list*/
/*The number 15 is the number of character of string file_collection*/
collection_name = buffer.substr(pos+15);
aux = new Collection();
aux->name = trim (collection_name);
/*Check for ".." substring for security issues*/
if ( collection_name.find("..") == string::npos ) {
aux->verify = 0;
collection_list->push_back (*aux);
}
continue;
}
}
}
file_conf.close();
return;
}
/**
* Sets configuration file to Pandora_Agent_Conf object instance.
*
@ -70,7 +118,7 @@ Pandora::Pandora_Agent_Conf::setFile (string filename) {
string buffer;
unsigned int pos;
Collection *aux;
if (this->key_values)
delete this->key_values;
this->key_values = new list<Key_Value> ();
@ -90,6 +138,22 @@ Pandora::Pandora_Agent_Conf::setFile (string filename) {
/* Ignore blank or commented lines */
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
/*Check if is a include*/
pos = buffer.find("include");
if (pos != string::npos){
string path_file;
unsigned pos_c;
path_file = buffer.substr(pos+8);
pos_c = path_file.find("\"");
/* Remove " */
while (pos_c != string::npos){
path_file.replace(pos_c, 1, "");
pos_c = path_file.find("\"",pos_c+1);
}
parseFile(path_file, aux);
}
/*Check if is a collection*/
pos = buffer.find("file_collection");
if(pos != string::npos) {

View File

@ -51,6 +51,7 @@ namespace Pandora {
static Pandora_Agent_Conf *getInstance ();
~Pandora_Agent_Conf ();
void parseFile(string path_file, Collection *aux);
void setFile (string filename);
string getValue (const string key);