Skip to content
Snippets Groups Projects
Commit 475273f5 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin
Browse files

Merge branch 'issue/86' into 'development'

Issue/86

See merge request !52
parents f920591f 75529c74
No related branches found
No related tags found
2 merge requests!103Merge dev -> master,!52Issue/86
Pipeline #
Showing with 130 additions and 62 deletions
......@@ -5,3 +5,6 @@ test/docker/*/*.sh
log/*
styleguide/*
Documentation/*
.vs/
bootstrap.log
......@@ -13,7 +13,7 @@ pattern:
- apt-get update && apt-get install -y git python
- git clone https://github.com/google/styleguide
- cd styleguide/cpplint
- ./cpplint.py --filter=-whitespace/blank_line,-build/include_what_you_use ../../src/agent/!(jsoncpp).cpp
- ./cpplint.py --filter=-whitespace/blank_line,-build/include_what_you_use,-readability/casting ../../src/agent/!(jsoncpp).cpp
compile:
stage: build
......
......@@ -7,9 +7,14 @@ set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
if(UNIX)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
else(WIN32)
add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_LIBS ON)
add_definitions(-DCURL_STATICLIB)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
# src : main, collect functions + jsoncpp library
file ( GLOB SOURCES src/agent/*.cpp )
......@@ -34,15 +39,17 @@ include_directories ( ${CPR_INCLUDE_DIRS} )
include_directories ( ${CURL_INCLUDE_DIRS} )
# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
add_subdirectory ( lib/dtwinver )
endif ()
# TODO: Incluir a biblioteca dtwinver ou encontrar outra similar
#if ( WIN32 )
# add_subdirectory ( lib/dtwinver )
#endif ()
# headers
include_directories ( "include" )
# include headers from boost lib
include_directories ( "${CMAKE_BINARY_DIR}/include" )
include_directories ( "build/Boost/src/Boost/" )
# scr = libboost
include ( "modules/boost.cmake" )
......@@ -55,7 +62,7 @@ target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES
add_dependencies ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
if ( WIN32 )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
#target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
else ()
# libudev
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
......
#pragma once
#include <iostream>
#ifdef __unix__
#include <sys/utsname.h>
#endif // __unix__
#include <fstream>
#include <cpr/cpr.h>
#include <json/json.h>
......
#pragma once
#ifdef __unix__
#include <libudev.h>
#endif // __unix__
#include <iostream>
#include <fstream>
#include <list>
......
#pragma once
#ifdef __unix__
#include <sys/utsname.h>
#endif // __unix__
#include <agent/open_file.h>
/**
......
#pragma once
#ifdef __unix__
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <malloc.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
#endif // __unix__
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <iostream>
#include <fstream>
#include <set>
......@@ -64,6 +66,7 @@ struct oldutmp {
#define UCHUNKSIZE 16384 /*!< How much we read at once. */
#ifdef __unix__
/** utmplist struct - Current utmp entry
* - The utmp file allows one to discover information about who is currently using the system
* - The struct has:
......@@ -76,6 +79,7 @@ struct utmplist {
struct utmplist *next;
struct utmplist *prev;
};
#endif // __unix__
/** user_log strcut (type of a list) - has info from a user
* - user login name
......
#pragma once
#ifdef __unix__
#include <sys/utsname.h>
#endif // __unix__
#include <time.h>
#include <iostream>
#include <agent/get_date.h>
......
......@@ -9,7 +9,9 @@
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/filesystem/fstream.hpp>
#ifdef __unix__
#include <sys/utsname.h>
#endif // __unix__
#include <cpr/cpr.h>
namespace pt = boost::posix_time;
......
#pragma once
#include <iostream>
#ifdef __unix__
#include <sys/utsname.h>
#endif // __unix__
#include <cpr/cpr.h>
#include <json/json.h>
#include <agent/inventory.h>
......
......@@ -4,37 +4,65 @@ cmake_minimum_required ( VERSION 2.8.7 )
include(ExternalProject)
if ( UNIX )
if (NOT Boost)
SET (Boost_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include/boost/)
SET (Boost_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib )
SET (BOOST_URL https://github.com/boostorg/boost.git )
SET (BOOST_BUILD ${CMAKE_CURRENT_BINARY_DIR})
SET (FILESYSTEM_LIB ${BOOST_BUILD}/lib/libboost_filesystem.a)
SET (SYSTEM_LIB ${BOOST_BUILD}/lib/libboost_system.a)
SET (REGEX_LIB ${BOOST_BUILD}/lib/libboost_regex.a)
SET (PROGRAM_OPTIONS_LIB ${BOOST_BUILD}/lib/libboost_program_options.a)
ExternalProject_Add( Boost
PREFIX Boost
GIT_REPOSITORY ${BOOST_URL}
GIT_SUBMODULES libs/asio libs/date_time libs/config libs/core libs/detail libs/io libs/iterator libs/predef libs/preprocessor libs/smart_ptr libs/throw_exception libs/system libs/filesystem libs/integer tools/build tools/bcp libs/serialization libs/interprocess libs/tokenizer libs/algorithm libs/program_options libs/regex libs/static_assert libs/thread libs/utility libs/numeric libs/range libs/array libs/bind libs/concept_check libs/lexical_cast libs/math libs/functional libs/assert libs/type_traits libs/mpl libs/move libs/container libs/any libs/type_index libs/function
UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system,regex,program_options --includedir=${CMAKE_BINARY_DIR}/include/
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 link=static install --libdir=${CMAKE_BINARY_DIR}/lib
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)
ADD_LIBRARY (Boost_LIB STATIC IMPORTED DEPENDS Boost)
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${FILESYSTEM_LIB})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${SYSTEM_LIB})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${REGEX_LIB})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${PROGRAM_OPTIONS_LIB})
endif()
if (NOT Boost)
if(UNIX)
SET (Boost_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include/boost/)
SET (Boost_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib )
SET (BOOST_URL https://github.com/boostorg/boost.git )
SET (BOOST_BUILD ${CMAKE_CURRENT_BINARY_DIR})
SET (FILESYSTEM_LIB ${BOOST_BUILD}/lib/libboost_filesystem.a)
SET (SYSTEM_LIB ${BOOST_BUILD}/lib/libboost_system.a)
SET (REGEX_LIB ${BOOST_BUILD}/lib/libboost_regex.a)
SET (PROGRAM_OPTIONS_LIB ${BOOST_BUILD}/lib/libboost_program_options.a)
else ()
SET (Boost_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include/boost/)
SET (Boost_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib )
SET (BOOST_URL https://github.com/boostorg/boost.git )
SET (BOOST_BUILD ${CMAKE_CURRENT_BINARY_DIR})
SET (FILESYSTEM_LIB ${BOOST_BUILD}/lib/libboost_filesystem-vc141-mt-gd-1_65.lib)
SET (SYSTEM_LIB ${BOOST_BUILD}/lib/libboost_system-vc141-mt-gd-1_65.lib)
SET (REGEX_LIB ${BOOST_BUILD}/lib/libboost_regex-vc141-mt-gd-1_65.lib)
SET (PROGRAM_OPTIONS_LIB ${BOOST_BUILD}/lib/libboost_program_options-vc141-mt-gd-1_65.lib)
endif ()
if (UNIX)
ExternalProject_Add( Boost
PREFIX Boost
GIT_REPOSITORY ${BOOST_URL}
GIT_SUBMODULES libs/asio libs/date_time libs/config libs/core libs/detail libs/io libs/iterator libs/predef libs/preprocessor libs/smart_ptr libs/throw_exception libs/system libs/filesystem libs/integer tools/build tools/bcp libs/serialization libs/interprocess libs/tokenizer libs/algorithm libs/program_options libs/regex libs/static_assert libs/thread libs/utility libs/numeric libs/range libs/array libs/bind libs/concept_check libs/lexical_cast libs/math libs/functional libs/assert libs/type_traits libs/mpl libs/move libs/container libs/any libs/type_index libs/function
UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system,regex,program_options --includedir=${CMAKE_BINARY_DIR}/include/
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 link=static install --libdir=${CMAKE_BINARY_DIR}/lib
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)
else ()
#add_definitions( -DBOOST_ALL_NO_LIB )
#set(Boost_USE_STATIC_LIBS ON)
ExternalProject_Add( Boost
PREFIX Boost
GIT_REPOSITORY ${BOOST_URL}
GIT_SUBMODULES libs/asio libs/config libs/core libs/date_time libs/detail libs/io libs/iterator libs/predef libs/preprocessor libs/smart_ptr libs/throw_exception libs/system libs/filesystem libs/integer tools/build tools/bcp libs/serialization libs/interprocess libs/tokenizer libs/algorithm libs/program_options libs/regex libs/static_assert libs/thread libs/utility libs/numeric libs/range libs/array libs/bind libs/concept_check libs/lexical_cast libs/math libs/functional libs/assert libs/type_traits libs/mpl libs/move libs/container libs/any libs/type_index libs/function libs/chrono libs/ratio libs/intrusive libs/spirit libs/winapi libs/tuple libs/exception libs/optional
#GIT_SUBMODULES libs/accumulators libs/algorithm libs/align libs/any libs/array libs/asio libs/assert libs/assign libs/atomic libs/bimap libs/bind libs/chrono libs/circular_buffer libs/compatibility libs/compute libs/concept_check libs/config libs/container libs/context libs/conversion libs/convert libs/core libs/coroutine libs/coroutine2 libs/crc libs/date_time libs/detail libs/disjoint_sets libs/dll libs/dynamic_bitset libs/endian libs/exception libs/fiber libs/filesystem libs/flyweight libs/foreach libs/format libs/function libs/function_types libs/functional libs/fusion libs/geometry libs/gil libs/graph libs/graph_parallel libs/hana libs/heap libs/icl libs/integer libs/interprocess libs/intrusive libs/io libs/iostreams libs/iterator libs/lambda libs/lexical_cast libs/local_function libs/locale libs/lockfree libs/log libs/logic libs/math libs/metaparse libs/move libs/mpi libs/mpl libs/msm libs/multi_array libs/multi_index libs/multiprecision libs/optional libs/parameter libs/phoenix libs/poly_collection libs/polygon libs/pool libs/predef libs/preprocessor libs/process libs/program_options libs/property_map libs/property_tree libs/proto libs/ptr_container libs/python libs/qvm libs/random libs/range libs/ratio libs/rational libs/regex libs/scope_exit libs/serialization libs/signals libs/signals2 libs/smart_ptr libs/sort libs/spirit libs/stacktrace libs/statechart libs/static_assert libs/system libs/test libs/thread libs/throw_exception libs/timer libs/tokenizer libs/tti libs/tuple libs/type_erasure libs/type_index libs/type_traits libs/typeof libs/units libs/unordered libs/utility libs/uuid libs/variant libs/vmd libs/wave libs/winapi libs/xpressive
UPDATE_COMMAND ./bootstrap.bat --with-toolset=msvc-14.1 --with-libraries=filesystem,system,regex,program_options,chrono --includedir=${CMAKE_BINARY_DIR}/include/
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 link=static install --libdir=${CMAKE_BINARY_DIR}/lib toolset=msvc-14.1
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)
endif ()
ADD_LIBRARY (Boost_LIB STATIC IMPORTED DEPENDS Boost)
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${FILESYSTEM_LIB})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${SYSTEM_LIB})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${REGEX_LIB})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${PROGRAM_OPTIONS_LIB})
endif()
......@@ -61,8 +61,11 @@ bool Curl::downloadAgent(std::string url, std::fstream* logFile,
agent->setRunName("agent.run");
boost::filesystem::path test_file(test_root / agent->getRunName());
#ifdef __unix__
FILE* fp = fopen(test_file.c_str(), "wb");
#elif _WIN32
FILE* fp;
#endif
if (!fp) {
agent->setMessage(__DATE__ + std::string(" - ERROR: Failed to ") +
std::string("create file on the disk."));
......
......@@ -30,7 +30,9 @@ std::string get_date() {
char buffer[20];
time(&rawtime);
#ifdef __unix__
localtime_r(&rawtime, timeinfo);
#endif // __unix__
// YYYY-MM-DD
strftime(buffer, 20, "%Y-%m-%d", timeinfo);
......
......@@ -22,7 +22,7 @@
/** We use here udev lib to get info about disks */
void get_scsi_disks(std::list<disk_t>& disks) { // NOLINT(runtime/references)
#ifdef __unix__
struct udev *udev;
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry, *links_list_entry;
......@@ -99,6 +99,7 @@ void get_scsi_disks(std::list<disk_t>& disks) { // NOLINT(runtime/references)
}
udev_unref(udev);
#endif
}
/** Get disks info (Model and size) */
......
......@@ -25,10 +25,9 @@ std::string get_macaddr() {
#ifdef WIN32
PIP_ADAPTER_INFO AdapterInfo;
DWORD dwBufLen = sizeof(AdapterInfo);
char *mac_addr = reinterpret_cast<char*>malloc(17);
char *mac_addr = (char*)malloc(17);
AdapterInfo = (reinterpret_cast<char*>IP_ADAPTER_INFO *)
malloc(sizeof(IP_ADAPTER_INFO));
AdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
if (AdapterInfo == NULL) {
throw std::string("Error allocating memory needed to call ") +
std::string("GetAdaptersinfo\n");
......@@ -38,8 +37,7 @@ std::string get_macaddr() {
// the dwBufLen variable
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {
AdapterInfo = (reinterpret_cast<char*>IP_ADAPTER_INFO *)
malloc(dwBufLen);
AdapterInfo = (IP_ADAPTER_INFO *)malloc(dwBufLen);
if (AdapterInfo == NULL) {
throw std::string("Error allocating memory needed to call ") +
std::string(" GetAdaptersinfo\n");
......@@ -51,10 +49,10 @@ std::string get_macaddr() {
// Contains pointer to current adapter info
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
snprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
/*snprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
pAdapterInfo->Address[0], pAdapterInfo->Address[1],
pAdapterInfo->Address[2], pAdapterInfo->Address[3],
pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
pAdapterInfo->Address[4], pAdapterInfo->Address[5]);*/
free(AdapterInfo);
return mac_addr;
}
......
......@@ -29,7 +29,9 @@ std::string get_time() {
char buffer[20];
time(&rawtime);
#ifdef __unix__
localtime_r(&rawtime, timeinfo);
#endif // __unix__
// HH:MM:SS
strftime(buffer, 20, "%H:%M:%S", timeinfo);
......
......@@ -64,6 +64,7 @@ char yesterday[7], today[7];
* Automatically reposition file pointer.
*/
static int uread(FILE *fp, struct utmp *u, int *quit) {
#ifdef __unix__
static int utsize, bpos;
static char buf[UCHUNKSIZE];
char tmp[1024];
......@@ -142,7 +143,7 @@ static int uread(FILE *fp, struct utmp *u, int *quit) {
bpos += UCHUNKSIZE;
memcpy(u, tmp, sizeof(struct utmp));
#endif // __unix__
return 1;
}
......@@ -153,6 +154,7 @@ static int uread(FILE *fp, struct utmp *u, int *quit) {
* .
* Case one of above options, saved in a list
*/
#ifdef __unix__
static void list(struct utmp *p, time_t t, int what) {
time_t tmp;
struct user_log * u = (struct user_log *)malloc(sizeof(struct user_log));
......@@ -205,9 +207,11 @@ static void list(struct utmp *p, time_t t, int what) {
users.insert(u->user);
}
}
#endif // __unix__
/** Check each line from utmp file that is opened by uread function */
static struct user_log * last_modified() {
#ifdef __unix__
FILE *fp; /* Filepointer of wtmp file */
struct utmp ut; /* Current utmp entry */
......@@ -497,6 +501,9 @@ static struct user_log * last_modified() {
}
fclose(fp);
#else
return NULL;
#endif // __unix__
}
/** Get number of users that logged/used the current computer in previous day */
......@@ -513,9 +520,11 @@ int get_user_count() {
ofstream wtmp_file;
wtmp_file.open(wtmp_path.c_str());
wtmp_file.close();
#ifdef __unix__
chown(wtmp_path.c_str(), getpwnam("root")->pw_uid,
getgrnam("tty")->gr_gid);
chmod(wtmp_path.c_str(), 664);
#endif // __unix__
}
time_t rawtime;
......
......@@ -55,7 +55,7 @@ Json::Value get_net_bandwidth() {
std::string str;
std::fstream time_file;
#ifdef __linux__
#ifdef __linux__
// net_band_file >> net_band_all_time;
reader.parse(net_band_file, net_band_all_time , false);
net_band_file.close();
......@@ -229,7 +229,6 @@ Json::Value get_net_bandwidth() {
net_band["data_net"]["packets_tranmitted"] = pack_tr - pack_tr_allt;
net_band["data_net"]["collect_time"] = str;
myfile.close();
#endif
return (net_band);
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment