From 1e5afce81e0ee97ce7a72eb10f88823d446f2bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lais=20Frig=C3=A9rio?= <lfs@inf.ufpr.br> Date: Tue, 6 Dec 2016 11:06:37 -0200 Subject: [PATCH] Parse config and proxy fle --- update/agent/CMakeLists.txt | 25 +++ update/agent/conf/datasid-conf.json | 11 + .../include/agent/linux/.datasid-agent.h.un~ | Bin 0 -> 11031 bytes .../include/agent/linux/.datasid-common.h.un~ | Bin 0 -> 5081 bytes .../agent/include/agent/linux/datasid-agent.h | 50 +++++ .../agent/include/agent/linux/datasid-check.h | 0 .../include/agent/linux/datasid-client.h | 0 .../include/agent/linux/datasid-common.h | 24 ++ .../agent/include/agent/linux/datasid-conf.h | 80 +++++++ .../agent/include/agent/linux/datasid-curl.h | 0 .../include/agent/linux/datasid-netmon.h | 0 .../agent/linux/datasid-network-usage.h | 0 .../agent/include/agent/linux/datasid-parse.h | 39 ++++ .../agent/include/agent/linux/datasid-proxy.h | 51 +++++ .../include/agent/linux/datasid-uninstall.h | 0 update/agent/include/agent/main.h | 13 ++ update/agent/src/client.cpp | 0 update/agent/src/client.h | 0 update/agent/src/linux/.datasid-agent.cpp.un~ | Bin 0 -> 10357 bytes update/agent/src/linux/datasid-agent.cpp | 107 +++++++++ update/agent/src/linux/datasid-check.cpp | 0 update/agent/src/linux/datasid-client.cpp | 0 update/agent/src/linux/datasid-common.cpp | 123 +++++++++++ update/agent/src/linux/datasid-conf.cpp | 205 ++++++++++++++++++ update/agent/src/linux/datasid-curl.cpp | 0 update/agent/src/linux/datasid-netmon.cpp | 0 .../agent/src/linux/datasid-network-usage.cpp | 0 update/agent/src/linux/datasid-parse.cpp | 152 +++++++++++++ update/agent/src/linux/datasid-proxy.cpp | 104 +++++++++ update/agent/src/linux/datasid-uninstall.cpp | 0 update/agent/src/main.cpp | 27 +++ 31 files changed, 1011 insertions(+) create mode 100644 update/agent/CMakeLists.txt create mode 100644 update/agent/conf/datasid-conf.json create mode 100644 update/agent/include/agent/linux/.datasid-agent.h.un~ create mode 100644 update/agent/include/agent/linux/.datasid-common.h.un~ create mode 100644 update/agent/include/agent/linux/datasid-agent.h create mode 100644 update/agent/include/agent/linux/datasid-check.h create mode 100644 update/agent/include/agent/linux/datasid-client.h create mode 100644 update/agent/include/agent/linux/datasid-common.h create mode 100644 update/agent/include/agent/linux/datasid-conf.h create mode 100644 update/agent/include/agent/linux/datasid-curl.h create mode 100644 update/agent/include/agent/linux/datasid-netmon.h create mode 100644 update/agent/include/agent/linux/datasid-network-usage.h create mode 100644 update/agent/include/agent/linux/datasid-parse.h create mode 100644 update/agent/include/agent/linux/datasid-proxy.h create mode 100644 update/agent/include/agent/linux/datasid-uninstall.h create mode 100644 update/agent/include/agent/main.h create mode 100644 update/agent/src/client.cpp create mode 100644 update/agent/src/client.h create mode 100644 update/agent/src/linux/.datasid-agent.cpp.un~ create mode 100644 update/agent/src/linux/datasid-agent.cpp create mode 100644 update/agent/src/linux/datasid-check.cpp create mode 100644 update/agent/src/linux/datasid-client.cpp create mode 100644 update/agent/src/linux/datasid-common.cpp create mode 100644 update/agent/src/linux/datasid-conf.cpp create mode 100644 update/agent/src/linux/datasid-curl.cpp create mode 100644 update/agent/src/linux/datasid-netmon.cpp create mode 100644 update/agent/src/linux/datasid-network-usage.cpp create mode 100644 update/agent/src/linux/datasid-parse.cpp create mode 100644 update/agent/src/linux/datasid-proxy.cpp create mode 100644 update/agent/src/linux/datasid-uninstall.cpp create mode 100644 update/agent/src/main.cpp diff --git a/update/agent/CMakeLists.txt b/update/agent/CMakeLists.txt new file mode 100644 index 00000000..00495959 --- /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 00000000..224b9fa8 --- /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 GIT binary patch literal 11031 zcmeHNUvC>l5O<T%*3ha@DnTVgrv%z0auO#Y6*Q>ex^-)jCYJxSjYJh~?$+^&^R0Dv zP8%v7`WZmt0Z@f_<7@B*;1lpv!3%vWs0akVS>HOBDuI_CLg+@CY;L?eJ3GJKow>ce zuDbVI{w4h&H}c>MI&<UJqsQ0(DCF<mpE&o)ufKe>IFm1ax%lnpcYgSOI+x3x0l$*Z zhf$#XP1=-EEs(0M?o3RQqx~>i!tbZS$G```N5M>7TF%{Exb<+1e;v!Mf5*RqMh1oX z%Rez2`V+MCWTjd8^gM8L;e*Epj$H21%TK5s$MgHMQ&iTy?LcjIBAO^q(tNS_=Jb4V z?i`h+9|f9Ri5lHrKN616R928;RycwrHFP_=Edoi)YAcYej;836?1>-}UDPv;tA1Mt zT@i7UX=?duO9r8G1@u;=D+A$?tEnae;d6!ZLSuQhRjJjXZiJ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>9*b)aZKIuBnf-G>c7t$mIuD49!8X4pkFQK!OU=CWG8t!rS5N8|= zR32=JK^z`YX24muq*VgAPqU1}o*2Q)gTv<R3|ad-ho{*YviSm$ogweFkH<UH|NRUZ z!`z*5aG-iN9y}Ku#7^1gEO1#*q*WqteU=Pd?E2GSb6R1}H&{Ye5@#C>(sN)-3?R4S zd?ia0*$Jr<K>I2Q8lkt>z-PgnChq^eD8`TRIs&%DSdx9n7M=A(S|#xN+Tb@jNb~Iy z<Ng@Gv*v4``Br%T{F5L3s26{#o4gyN$>`bZBdmgv<<-as%h_sVC!|V1^QYu$Om>!? zHV(h*XZJ_UwVT9kn(Y2ac7KGgU!;D2<kfxdkC;I6FJB_T?zsB}Aeo2o*2$5KqZeO{ j%%T@NAyq>3`q@OUu|Y0E=#6tpd*t}H*NYbK{rJsa@wobX literal 0 HcmV?d00001 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 GIT binary patch literal 5081 zcmeHLOKa6Y6i#oeHc+A7)<;_(k%IK48|lW14|=N`MZs2GD3>&u8wQe0NOEh7DD(&T z8{8NC2ZBGqjiBhxl|@{*vu<4I`6e^T+`9F;%7M9a=Q}5vIp@nclgWJ^y<Cf1V%KW? z3O>JD`TqL(r?-2%AHV(h@Fi@&|9N|7^o{+fIlug(Wm(n*YFe7~XMoxv1)$f>dU)~i z%^_$TR{NbYXs8|?RA^FulT;&(*8RVW0MRia>9DN56Z>vEN8^#{Bz1$xbwunj8jnr$ z*bBQpb1rj{<tcNcD+D(y*dvt3!QZGK@^zq)@oq*oPV7c3OI(jRS?(_tD(kQpx>@Ed zizpKDQvz)}N%@AGvr9BMV%x<8j_>Afi>J73v;;#DC~U06l2mMNEsMAV)A161!q)Gx zbc1_L&pcw=JkA}Th3*!xV`}VfWvgOkGvO(_B?4%gg{GU(BG_umS*Grd>lMl)cBh-` zdk@=5cRl1De3-QD4Z(dUV|lA^Vy5tE7S<D$mS!VwOy$W+c~`q->Q7br2c>_e0Zm{X zt&Cdmb%s_gr#@pSdYvv!rYe)Q%KK7ntWT;}izt+OOiwn7!k`MktmBC|li{K%D!mGU zp+0S@s~{K_<VJM^BMgQK)^WTb5sQ#fFw|!&)xJ0wMigt%P1l=|FbrrNy#^{6hRLA) zOg|x4VT*@4<9^$dPyfvIfD!28cR^*uISLdqV}Wu8iRL6J>+sFlrNwPoP*FSw;hqu{ z*SetUX!O0Of;zdspn?t*Q_#>;P!(mMXo#8?*w>WlX!N}&%BD=pbOxQ*G{~J%qYGG1 zxmSX!d2OfY1a^R$7ElXJO8rWsBhjy(=$td@M0V-$gT#Z=EcSUvkp*%N8cP9jl44*r zSw>{~@|Vb(mt+kTIaP)pv&k&$K@@2qNuMrY2m+C<Qfkt4B>L48Y1hmQGv@&fbQ<Wy zKI=Gb^&Zo1OOzlUvjP<&mT1p@NLKX$qds8h!;$$~t&b@60mC>w{NDoxWoPf+Y3`e( rlqDG$J^<BwCxXydp)!0!mf=RRQ({*frl#Lpdq2v^&o7JHUw8fho&K4d literal 0 HcmV?d00001 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 00000000..16325293 --- /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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..3f884557 --- /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 00000000..f3564a7f --- /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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..990c787d --- /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 00000000..95e971eb --- /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 00000000..e69de29b diff --git a/update/agent/include/agent/main.h b/update/agent/include/agent/main.h new file mode 100644 index 00000000..dc7552db --- /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 00000000..e69de29b diff --git a/update/agent/src/client.h b/update/agent/src/client.h new file mode 100644 index 00000000..e69de29b 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 GIT binary patch literal 10357 zcmeHN&u<$=6n4|l)}X4F6#7H7PeCGf>YqtliKHnwPTX2e)5wl#BUGY^cN`C0@0i`$ zq-ljv{|<^c(*yqjC&Ud21Q!lmD<qCcAaN?+8?O@=C8Y;)DBY*bj(6UhZ{NK4cIVS> z-dCM38s40KoEVz;{obEX9-ce@+NU3VeeK7;Mt*zp{b$F%eDv_A&*$c64}JArB9XX= zb~fn<BLd~DHg%_?y_8s&p2<+}EIkdANwhc74xk-DW8uEv61OHlTpwobaANfb)<TAQ zojtND)jxj%u~7Yixc`qMaBK4RH#QxK#2+XAfz2tumLI3G?r!;Ny=^E}PSZr8a6UUx zC|;y8lJ9GBBrH1J(1@ncR8|;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t%bBFL$nC6c z+gX~l-m=wmu!a*!<iXITOEfAz4%I0ClAh!8g<kD1rP%ZT!UM}2m?s=$_(+&T#Jr&& zjeYOI8@{!?;Xsc!jNyuW|1f9Z)a+fIQT{kz!)SfsTyp+i;enX<aTNAbkiVZ}-WT(} zhy};IFXnwt%=?lr0Pi~un#uIpQnab5myh`|Q?M){+8>!kFmo8;^O!ks6!ufV9DcFP zVQ6>e_pJJixF2Wi(14Ge%{YSt0omW5cm?}L%>82S7jwV(onQRU??rm&cWO88_Y%GI zW1?_)U~^;=!NlPtkHyrFqp+U>;&93mhl9IQzh{(Z#QZp6M+RKvWO4%elX09t4#K_) z5_l_SelhclnP1HOV&?ZEF~75WGQXzw0&^eR#{d7D?;!Q#eUh0({~yj`_P`O@R{?uy bS@tm8qksH=NaxY|-+ce=L;r;bzdrgKYII9z literal 0 HcmV?d00001 diff --git a/update/agent/src/linux/datasid-agent.cpp b/update/agent/src/linux/datasid-agent.cpp new file mode 100644 index 00000000..db67ee6c --- /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 00000000..e69de29b diff --git a/update/agent/src/linux/datasid-client.cpp b/update/agent/src/linux/datasid-client.cpp new file mode 100644 index 00000000..e69de29b diff --git a/update/agent/src/linux/datasid-common.cpp b/update/agent/src/linux/datasid-common.cpp new file mode 100644 index 00000000..839c735a --- /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 00000000..749c3394 --- /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 00000000..e69de29b diff --git a/update/agent/src/linux/datasid-netmon.cpp b/update/agent/src/linux/datasid-netmon.cpp new file mode 100644 index 00000000..e69de29b 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 00000000..e69de29b diff --git a/update/agent/src/linux/datasid-parse.cpp b/update/agent/src/linux/datasid-parse.cpp new file mode 100644 index 00000000..5807c703 --- /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 00000000..d18989b3 --- /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 00000000..e69de29b diff --git a/update/agent/src/main.cpp b/update/agent/src/main.cpp new file mode 100644 index 00000000..1afa6e75 --- /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 -- GitLab