diff --git a/update/agent/CMakeLists.txt b/update/agent/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0049595955277afd24d97d07710b46ce70fa191c --- /dev/null +++ b/update/agent/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required( VERSION 2.6 ) + +project( datasid-agent ) + +# version number +set ( VERSION_MAJOR 0 ) +set ( VERSION_MINOR 0 ) + +# cpr requires c++11 +set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" ) + +# src : main +file ( GLOB SOURCES src/*.cpp + +# src : collect functions - depend on OS +if ( WIN32 ) + file ( GLOB SOURCES ${SOURCES} src/windows/*.cpp ) +else () # if( UNIX ) + file ( GLOB SOURCES ${SOURCES} src/linux/*.cpp ) +endif () + +# compile +set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" ) +add_executable ( datasid-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} ) + diff --git a/update/agent/conf/datasid-conf.json b/update/agent/conf/datasid-conf.json new file mode 100644 index 0000000000000000000000000000000000000000..224b9fa8003458ff9e4a47943712de94bfd8f334 --- /dev/null +++ b/update/agent/conf/datasid-conf.json @@ -0,0 +1,11 @@ +{ +"dataDir" : "/data", +"logDir" : "/log", +"proxyConf" : "/conf/proxy.json", +"delay" : "86400", // 24 hours +"daysToExpireLog" : "31", // 1 month +"updateTries" : "3", +"updateTimeOut":"100", +"webService": "http://simmc.c3sl.ufpr.br/axis2/services/DataSID" +} + diff --git a/update/agent/include/agent/linux/.datasid-agent.h.un~ b/update/agent/include/agent/linux/.datasid-agent.h.un~ new file mode 100644 index 0000000000000000000000000000000000000000..beef159e5d139bc9212337c2702eb57d9438d0c0 Binary files /dev/null and b/update/agent/include/agent/linux/.datasid-agent.h.un~ differ diff --git a/update/agent/include/agent/linux/.datasid-common.h.un~ b/update/agent/include/agent/linux/.datasid-common.h.un~ new file mode 100644 index 0000000000000000000000000000000000000000..b1b377e888c141e0431a9148c0605a41aeda87c4 Binary files /dev/null and b/update/agent/include/agent/linux/.datasid-common.h.un~ differ diff --git a/update/agent/include/agent/linux/datasid-agent.h b/update/agent/include/agent/linux/datasid-agent.h new file mode 100644 index 0000000000000000000000000000000000000000..16325293597cb2754319fab9aaed563f15d00032 --- /dev/null +++ b/update/agent/include/agent/linux/datasid-agent.h @@ -0,0 +1,50 @@ +#ifndef __agent__ +#define __agent__ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include <iostream> +#include <cstring> + +using namespace std; + +class Agent{ + private: + string confDir; + string logFile; + string prefix; + string version; + + public: + void setConfDir(string); + void setLogFile(string, string); + void setPrefix(string, int); + void setVersion(string); + + string getConfDir() const; + string getLogFile() const; + string getPrefix() const; + string getVersion() const; +}; + +string cutString( string str, int tot ); +int datasid_agent(); +bool prefixIsSet( string prefix ); +#endif diff --git a/update/agent/include/agent/linux/datasid-check.h b/update/agent/include/agent/linux/datasid-check.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/include/agent/linux/datasid-client.h b/update/agent/include/agent/linux/datasid-client.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/include/agent/linux/datasid-common.h b/update/agent/include/agent/linux/datasid-common.h new file mode 100644 index 0000000000000000000000000000000000000000..3f8845576b4f5d9acc3d320e4b6f8ba4265265f2 --- /dev/null +++ b/update/agent/include/agent/linux/datasid-common.h @@ -0,0 +1,24 @@ +#ifndef __common__ +#define __common__ +#include "datasid-agent.h" +#include <sys/stat.h> +#include "datasid-conf.h" +#include "datasid-proxy.h" + +using namespace std; + +class Common{ + private: + string defaultConf; + + public: + void setDefaultConf(string, string); + + string getDefaultConf() const; + }; + +void checkVersionFileExist(Agent& agent); +void createDirectories(Agent agent, Conf conf); +bool fileExist(const char * file); +bool datasid_common(Conf& conf, Proxy& proxy, Agent& agent, Common& Common); +#endif diff --git a/update/agent/include/agent/linux/datasid-conf.h b/update/agent/include/agent/linux/datasid-conf.h new file mode 100644 index 0000000000000000000000000000000000000000..f3564a7f0fd066ec21714635b6feaefbbc4498a6 --- /dev/null +++ b/update/agent/include/agent/linux/datasid-conf.h @@ -0,0 +1,80 @@ +#ifndef __conf__ +#define __conf__ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include <iostream> +#include <cstring> +#include <cstdlib> +#include <locale> +#include <sstream> +#include <map> +#include "datasid-agent.h" +#include "datasid-parse.h" + +using namespace std; + +class Conf{ + private: + string dataDir; + string logDir; + string proxyConf; + string webService; + + int delay; + int daysToExpireLog; + int updateTries; + int updateTimeOut; + + public: + void setDataDir(string); + void setLogDir(string); + void setProxyConf(string); + void setWebService(string); + + void setDelay(int); + void setDaysToExpireLog(int); + void setUpdateTries(int); + void setUpdatTimeOut(int); + + string getDataDir() const; + string getLogDir() const; + string getProxyConf() const; + string getWebService() const; + + int getDelay() const; + int getDaysToExpireLog() const; + int getUpdateTries() const; + int getUpdateTimeOut() const; + + int sizeDataDir(); + int sizeLogDir(); + int sizeProxyConf(); + int sizeWebService(); + int sizeDelay(); + int sizeDaysToExpireLOg(); + int sizeUpdateTries(); + int sizeUpdateTimeOut(); + + }; + +bool checkFileConf(Conf& conf, Agent agent); +Conf datasid_conf(Agent agent); +#endif \ No newline at end of file diff --git a/update/agent/include/agent/linux/datasid-curl.h b/update/agent/include/agent/linux/datasid-curl.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/include/agent/linux/datasid-netmon.h b/update/agent/include/agent/linux/datasid-netmon.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/include/agent/linux/datasid-network-usage.h b/update/agent/include/agent/linux/datasid-network-usage.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/include/agent/linux/datasid-parse.h b/update/agent/include/agent/linux/datasid-parse.h new file mode 100644 index 0000000000000000000000000000000000000000..990c787d21207fc55ecbeb1015bdcb29afae78a9 --- /dev/null +++ b/update/agent/include/agent/linux/datasid-parse.h @@ -0,0 +1,39 @@ +#ifndef __parse__ +#define __parse__ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include <iostream> +#include <fstream> +#include <cstring> +#include <cstdlib> +#include <locale> +#include <map> + +using namespace std; + +bool isvalid (string & line); +void normalize (string & str); +void parse ( string& line, map<string, string>& content); +bool readfile (const string file, map<string,string>& content); +bool spaceonly (const string& line); +void trim (string& str); + +#endif \ No newline at end of file diff --git a/update/agent/include/agent/linux/datasid-proxy.h b/update/agent/include/agent/linux/datasid-proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..95e971eb7581160abc567361552e30605a1d4eb3 --- /dev/null +++ b/update/agent/include/agent/linux/datasid-proxy.h @@ -0,0 +1,51 @@ +#ifndef __proxy__ +#define __proxy__ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include <locale> +#include <sstream> +#include "datasid-agent.h" +#include "datasid-conf.h" +#include "datasid-parse.h" + +using namespace std; + +class Proxy{ + private: + string host; + string port; + string user; + string password; + + public: + void setHost(string); + void setPort(string); + void setUser(string); + void setPassword(string); + + string getHost() const; + string getPort() const; + string getUser() const; + string getPassword() const; +}; + +Proxy datasid_proxy(Conf conf); +#endif \ No newline at end of file diff --git a/update/agent/include/agent/linux/datasid-uninstall.h b/update/agent/include/agent/linux/datasid-uninstall.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/include/agent/main.h b/update/agent/include/agent/main.h new file mode 100644 index 0000000000000000000000000000000000000000..dc7552db6aeede44bbc8066f10289101095848a5 --- /dev/null +++ b/update/agent/include/agent/main.h @@ -0,0 +1,13 @@ +#ifndef __main__ +#define __main__ +#include <cstring> +#include <fstream> +#include <iostream> +#include "linux/datasid-proxy.h" +#include "linux/datasid-common.h" +#include "linux/datasid-agent.h" +#include "linux/datasid-conf.h" + +bool fileExist(const string& file); +int main(); +#endif diff --git a/update/agent/src/client.cpp b/update/agent/src/client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/client.h b/update/agent/src/client.h new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/linux/.datasid-agent.cpp.un~ b/update/agent/src/linux/.datasid-agent.cpp.un~ new file mode 100644 index 0000000000000000000000000000000000000000..49032e34321482cf2da2dc8b4df62a3bafe9481c Binary files /dev/null and b/update/agent/src/linux/.datasid-agent.cpp.un~ differ diff --git a/update/agent/src/linux/datasid-agent.cpp b/update/agent/src/linux/datasid-agent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db67ee6c7170ee2bf374684682e420f9bea8ad06 --- /dev/null +++ b/update/agent/src/linux/datasid-agent.cpp @@ -0,0 +1,107 @@ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include "../../include/agent/main.h" + +using namespace std; + +/* + * set Functions + */ + +void Agent::setConfDir(string dir){ + this->confDir = this->prefix + dir; +} + +void Agent::setLogFile(string logDir, string file){ + this->logFile = logDir + file; +} + +void Agent::setPrefix(string p, int t){ + this->prefix = cutString(p,t); +} + +void Agent::setVersion(string v){ + this->version = v; +} + +/* + * get Functions + */ + +string Agent::getConfDir() const{ + return this->confDir; +} + +string Agent::getLogFile() const{ + return this->logFile; +} + +string Agent::getPrefix() const{ + return this->prefix; +} + +string Agent::getVersion() const{ + return this->version; +} + +/* + * cutString Function: + * get the absolute path of the agent + */ + +string cutString( string str, int tot){; + int i=str.size(), count=0; + while(i-->-1) + if(str[i] == '/') + if(++count == tot) + break; + return str.substr(0,i); +} + +bool prefixIsSet(string prefix){ + if(prefix.size() == 0) + throw " ERROR: Prefix not set. "; + return true; +} + +int datasid_agent(){ + Agent agent; + Conf conf; + Proxy proxy; + Common common; + + /* Set agent prefix */ + agent.setPrefix(__FILE__, 3); + + /* Run datasid-common.cpp */ + if(!datasid_common(conf, proxy, agent, common)) + exit(1); + + /* Check if agent prefix was setted */ + try{ + prefixIsSet(agent.getPrefix()); + }catch(const char* msg){ + cout << __DATE__ << msg << "here" << endl; + exit(1); + } + + return 1; +} diff --git a/update/agent/src/linux/datasid-check.cpp b/update/agent/src/linux/datasid-check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/linux/datasid-client.cpp b/update/agent/src/linux/datasid-client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/linux/datasid-common.cpp b/update/agent/src/linux/datasid-common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..839c735adf47357fcb37500afec7b009cebcc1e0 --- /dev/null +++ b/update/agent/src/linux/datasid-common.cpp @@ -0,0 +1,123 @@ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include "../../include/agent/linux/datasid-conf.h" +#include "../../include/agent/linux/datasid-proxy.h" +#include "../../include/agent/linux/datasid-agent.h" +#include "../../include/agent/linux/datasid-common.h" +#include "../../include/agent/main.h" +using namespace std; + +/* + * set Functions + */ + +void Common::setDefaultConf(string defaultConf, string prefix){ + this->defaultConf = prefix + defaultConf; +} + +/* + * get Functions + */ + +string Common::getDefaultConf() const{ + return this->defaultConf; +} + +/* + * fileExist Function + * verify if a file exist + */ + +bool fileExist(const string& file){ + ifstream myFile (file.c_str(), ios::in); + if(myFile.is_open()){ + myFile.close(); + return true; + } + myFile.close(); + return false; +} + +/* + * Create "data" and "log" directories if needed + * c_str() - converte c++ string to c string + */ + +void createDirectories(Agent agent, Conf conf){ + mkdir(conf.getLogDir().c_str(), 0700); + mkdir(conf.getDataDir().c_str(), 0700); +} + +/* + * checkVersionFileExist Function + * check if version file exist and set version variable. + * Otherwise, setted 0.0.0 + */ + +void checkVersionFileExist(Agent& agent){ + string versionFile = agent.getConfDir() + "/version"; + ifstream myFile (versionFile.c_str(), ios::in); + + if(myFile.is_open()){ + string cnt; + myFile >> cnt; + agent.setVersion(cnt); + } + + if(agent.getVersion().size() == 0) + agent.setVersion("0.0.0"); + + myFile.close(); +} + +bool datasid_common(Conf& conf, Proxy& proxy, Agent& agent, Common& common){ + + try{ + prefixIsSet(agent.getPrefix()); + }catch(const char* msg){ + cout << __DATE__ << msg << endl; + return false; + } + + /* Read config file and declare only valid variables */ + + common.setDefaultConf("/conf/datasid-conf.json", agent.getPrefix()); + if(!fileExist(common.getDefaultConf())){ + cout << __DATE__ << "- ERROR: Config file not found. " << endl; + return false; + } else + conf = datasid_conf(agent); + + /* Read proxy file and declare only valid variables */ + + if(!fileExist(conf.getProxyConf())) + cout << __DATE__ << "- WARNING: Proxy file not found. " << endl; + else + proxy = datasid_proxy(conf); + + createDirectories(agent, conf); + + agent.setConfDir("/conf"); + agent.setLogFile( conf.getLogDir(), "/datasid-agent.log" ); + checkVersionFileExist(agent); + + return true; +} \ No newline at end of file diff --git a/update/agent/src/linux/datasid-conf.cpp b/update/agent/src/linux/datasid-conf.cpp new file mode 100644 index 0000000000000000000000000000000000000000..749c3394baf6e56a84fa9d94b6b77512a9ad6633 --- /dev/null +++ b/update/agent/src/linux/datasid-conf.cpp @@ -0,0 +1,205 @@ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include "../../include/agent/linux/datasid-conf.h" +#include <map> +#include "../../include/agent/linux/datasid-agent.h" +#include "../../include/agent/main.h" +#include "../../include/agent/linux/datasid-parse.h" + +using namespace std; + +/* + * set Functions + */ + +void Conf::setDataDir(string data){ + this->dataDir = data; +} + +void Conf::setLogDir(string log){ + this->logDir = log; +} + +void Conf::setProxyConf(string p){ + this->proxyConf = p; +} + +void Conf::setWebService(string web){ + this->webService = web; +} + +void Conf::setDelay(int d){ + this->delay = d; +} + +void Conf::setDaysToExpireLog(int d){ + this->daysToExpireLog = d; +} + +void Conf::setUpdateTries(int u){ + this->updateTries = u; +} + +void Conf::setUpdatTimeOut(int u){ + this->updateTimeOut = u; +} + +/* + * get Functions + */ + +string Conf::getDataDir() const{ + return this->dataDir; +} + +string Conf::getLogDir() const{ + return this->logDir; +} + +string Conf::getProxyConf() const{ + return this->proxyConf; +} + +string Conf::getWebService() const{ + return this->webService; +} + +int Conf::getDelay() const{ + return this->delay; +} + +int Conf::getDaysToExpireLog() const{ + return this->daysToExpireLog; +} + +int Conf::getUpdateTries() const{ + return this->updateTries; +} + +int Conf::getUpdateTimeOut() const{ + return this->updateTimeOut; +} + +/* + * size Functions + * check if variables were setted.\ + */ + +int Conf::sizeDataDir() { + return this->dataDir.size(); +} + +int Conf::sizeLogDir() { + return this->logDir.size(); +} + +int Conf::sizeProxyConf() { + return this->proxyConf.size(); +} + +int Conf::sizeWebService() { + return this->webService.size(); +} + +int Conf::sizeDelay() { + ostringstream convert; + convert << this->delay; + return (convert.str()).size(); +} + +int Conf::sizeDaysToExpireLOg() { + ostringstream convert; + convert << this->daysToExpireLog; + return (convert.str()).size(); +} + +int Conf::sizeUpdateTries() { + ostringstream convert; + convert << this->updateTries; + return (convert.str()).size(); +} + +int Conf::sizeUpdateTimeOut() { + ostringstream convert; + convert << this->updateTimeOut; + return (convert.str()).size(); +} + +/* + * setConf Function + * If variables from config file setted, + * then set the conf object + */ + +bool setConf(Conf& conf, Agent agent, map<string,string>& content){ + if(content.count("DATADIR") == 0 || + content.count("LOGDIR") == 0 || + content.count("PROXYCONF") == 0 || + content.count("WEBSERVICE") == 0|| + content.count("DELAY") == 0 || + content.count("DAYSTOEXPIRELOG") == 0 || + content.count("UPDATETRIES") == 0 || + content.count("UPDATETIMEOUT") == 0 ) + return false; + + /* + * agent.getPrefix() contains the absolute path of the agent. + */ + + string dataDir = agent.getPrefix() + content["DATADIR"]; + string dataLog = agent.getPrefix() + content["LOGDIR"]; + string proxyConf = agent.getPrefix() + content["PROXYCONF"]; + string webService = content["WEBSERVICE"]; + int delay = atoi(content["DELAY"].c_str()); /* 24 hours */ + int daysToExpireLog = atoi(content["DAYSTOEXPIRELOG"].c_str()); /* 1 month */ + int updateTries = atoi(content["UPDATETRIES"].c_str()); + int updateTimeOut = atoi(content["UPDATETIMEOUT"].c_str()); + + conf.setDataDir(dataDir); + conf.setLogDir(dataLog); + conf.setProxyConf(proxyConf); + conf.setWebService(webService); + + conf.setDelay(delay); + conf.setDaysToExpireLog(daysToExpireLog); + conf.setUpdateTries(updateTries); + conf.setUpdatTimeOut(updateTimeOut); + + return true; +} + +Conf datasid_conf(Agent agent){ + map<string, string> content; + string confFile = agent.getPrefix() + "/conf/datasid-conf.json"; + Conf conf; + + if(readfile(confFile, content)){ + if(!setConf(conf, agent, content)){ + cout << __DATE__ << " ERROR: to parse variables from config file." << endl; + exit(1); + } + }else { + cout << __DATE__ << " ERROR: config file not found." << endl; + exit(1); + } + + return conf; +} \ No newline at end of file diff --git a/update/agent/src/linux/datasid-curl.cpp b/update/agent/src/linux/datasid-curl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/linux/datasid-netmon.cpp b/update/agent/src/linux/datasid-netmon.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/linux/datasid-network-usage.cpp b/update/agent/src/linux/datasid-network-usage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/linux/datasid-parse.cpp b/update/agent/src/linux/datasid-parse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5807c703c668c826521f415d62611cb88775a1c1 --- /dev/null +++ b/update/agent/src/linux/datasid-parse.cpp @@ -0,0 +1,152 @@ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include "../../include/agent/linux/datasid-parse.h" +/* + * Erases leading tabs, leading spaces; trailing tabs, trailing spaces. + */ + +void trim (string& str){ + int i = 0; + + while (i < (int) str.length() && (str[i] == ' ' || str[i] == '\t')) + ++i; + + if (i > 0) + str.erase (0, i); + + int j = i = str.length(); + + while (i > 0 && (str[i - 1] == ' ' || str[i - 1] == '\t')) + --i; + + if (i < j) + str.erase (i, j); +} + +/* + * Erases tabs and spaces between the variable's name and its value. + */ + +void normalize (string & str){ + trim (str); + + size_t i, j; + i = j = 0; + + while (i < str.length()) { + if (str[i] == ' ' || str[i] == '\t') { + j = i + 1; + + while (j < str.length() && (str[j] == ' ' || str[j] == '\t')) + ++j; + + if (j == i) + str.erase (i, 1); + else + str.erase (i, j - i); + } + else + ++i; + } +} + +/* + * Check if a line consists only of spaces and tabs + */ + +bool spaceonly (const string& line){ + for (int i = 0, j = line.length(); i < j; ++i) + if (line[i] != ' ' && line[i] != '\t') + return false; + return true; +} + +/* + * Check if a line is valid + */ + +bool isvalid (string& line) { + normalize (line); + int i = 0; + + if (line[i] == '[') { + int j = line.find_last_of (']'); + + if (j == std::string::npos) + return false; + + if (j - i == 1) + return false; + } + + else if (line[i] == ';' || line[i] == '#' || (line[i] == '/' && line[i + 1] == '/')) + return false; + + else if (line[i] == '=' || line[i] == ']' || line[i] == '{' || line[i] == '}') + return false; + + else if (line[i] = '"'){ + int j = line.find_last_of (':'); + if (j == i || j == -1) + return false; + + if (j == line.length()) + return false; + } + + return true; +} + +void parse ( string& line, map<string, string>& content){ + locale loc; + // if the line is a variable + value + if (line[0] == '"') { + + string name = line.substr (1, line.find (':')-2); + for(int i = 0; i < name.length(); i++) + name[i] = toupper(name[i], loc); + + string value = line.substr (line.find (':')+2); + value = value.substr(0,value.find ('"')); + + content[name] = value; + } +} + +bool readfile (const string file, map<string,string>& content) { + content.clear(); + + ifstream config (file.c_str(), ios::in); + + if (!config.is_open()) + return false; + + string section; + string buffer; + + while (getline (config, buffer, '\n')){ + if (!spaceonly (buffer)) + if (isvalid (buffer)) + parse ( buffer, content); + } + + return true; +} \ No newline at end of file diff --git a/update/agent/src/linux/datasid-proxy.cpp b/update/agent/src/linux/datasid-proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d18989b31a70255e3cfe40f1449c1036b105dc14 --- /dev/null +++ b/update/agent/src/linux/datasid-proxy.cpp @@ -0,0 +1,104 @@ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include "../../include/agent/linux/datasid-conf.h" +#include "../../include/agent/linux/datasid-parse.h" +#include "../../include/agent/linux/datasid-proxy.h" +#include "../../include/agent/linux/datasid-agent.h" + +using namespace std; + +/* + * set Functions + */ + +void Proxy::setHost(string h){ + this->host = h; +} + +void Proxy::setPort(string p){ + this->port = p; +} + +void Proxy::setUser(string u){ + this->user = u; +} + +void Proxy::setPassword(string p){ + this->password = p; +} + +/* + * get Functions + */ + +string Proxy::getHost() const{ + return this->host; +} + +string Proxy::getPort() const{ + return this->port; +} + +string Proxy::getUser() const{ + return this->user; +} + +string Proxy::getPassword() const{ + return this->password; +} + + +bool setProxy(Proxy& proxy, map<string,string>& content){ + if(content.count("PROXYHOST") == 0 || + content.count("PROXYPORT") == 0 || + content.count("PROXYUSER") == 0 || + content.count("PROXYPASSWORD") == 0) + return false; + + proxy.setHost(content["PROXYHOST"] ); + proxy.setPort(content["PROXYPORT"]); + proxy.setUser(content["PROXYUSER"]); + proxy.setPassword(content["PROXYPASSWORD"]); + + + return true; +} + +/* + * I suppose there are a file "proxy" that contain + * host, port, user and password variables. + */ + +Proxy datasid_proxy(Conf conf){ + Proxy proxy; + map<string,string> content; + string proxyFile = conf.getProxyConf(); + + if(readfile(proxyFile, content)){ + if(!setProxy(proxy, content)){ + cout << __DATE__ << " ERROR: to parse variables from proxy file." << endl; + exit(1); + } + } else + cout << __DATE__ << " WARNING: proxy file not found." << endl; + + return proxy; +} \ No newline at end of file diff --git a/update/agent/src/linux/datasid-uninstall.cpp b/update/agent/src/linux/datasid-uninstall.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/update/agent/src/main.cpp b/update/agent/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1afa6e755ebe6dc8dea63c49b4dc0bf68ba5fd9e --- /dev/null +++ b/update/agent/src/main.cpp @@ -0,0 +1,27 @@ +/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of datasid + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include "../include/agent/main.h" + +int main(){ + datasid_agent(); + + return 0; +} \ No newline at end of file