...
 
Commits (21)
......@@ -7,4 +7,4 @@ styleguide/*
Documentation/*
.vs/
bootstrap.log
.vscode
cache:
paths:
- build/Boost/src/Boost
stages:
- lint
- build
......@@ -29,7 +33,7 @@ compileUnix:
libudev-dev
- git submodule init
- git submodule update --init --recursive
- mkdir build
- mkdir -p build
- cd build
- cmake -DCURL_STATICLIB=ON ..
- make
......@@ -38,25 +42,54 @@ compileUnix:
- ./generate_agent.sh -idp=1234 -ws=www.C3Sl.ufpr.br -pch=mumm -pcp=6666 -pcu=ninguem -pcpasswd=123mudar -prj=simmc
- chmod +x agent-1234.run
compileWin:
compileWin32:
stage: build
artifacts:
paths:
- agent-1234.exe
- agent-32.exe
tags:
- windows
- inno
script:
- set PATH=%PATH%;C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build
- call vcvarsall.bat x86
- echo "Estágio 'build'"
- dpkg --add-architecture i386
- apt-get update && apt-get install -y build-essential cmake git makeself
libudev-dev g++-mingw-w64-i686
- git submodule init
- git submodule update --init --recursive
- rd /s /q build
- call mkdir build
- mkdir -p build
- cd build
- cmake .. -G "NMake Makefiles"
- nmake
- cd ..
- iscc generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=mumm /Dpcp=6666 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- cmake -D CMAKE_TOOLCHAIN_FILE=mingw_cross_toolchain_32-bit.cmake ..
- make
- su inno
- Xvfb :98 &
- export DISPLAY=:98
- cd /
- wine /home/inno/iscc ./builds/simmctic/agent/generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=mumm /Dpcp=6666 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- mv ./builds/simmctic/agent/agent-1234.exe ./builds/simmctic/agent/agent-32.exe
compileWin64:
stage: build
artifacts:
paths:
- agent-64.exe
tags:
- inno
script:
- echo "Estágio 'build'"
- apt-get update && apt-get install -y build-essential cmake git makeself
libudev-dev g++-mingw-w64-x86-64
- git submodule init
- git submodule update --init --recursive
- mkdir -p build
- cd build
- cmake -D CMAKE_TOOLCHAIN_FILE=mingw_cross_toolchain_64-bit.cmake ..
- make
- su inno
- Xvfb :98 &
- export DISPLAY=:98
- cd /
- wine /home/inno/iscc ./builds/simmctic/agent/generate_agent.iss /Didp=1234 /Dws=www.C3Sl.ufpr.br /Dpch=mumm /Dpcp=6666 /Dpcu=ninguem /Dpcpasswd=123mudar /Dprj=simmc /Dversion=1.0.0
- mv ./builds/simmctic/agent/agent-1234.exe ./builds/simmctic/agent/agent-64.exe
testDebian:
stage: test
......@@ -109,21 +142,7 @@ testOpensuse:
dependencies:
- compileUnix
testWin7:
stage: test
tags:
- windows
script:
- if exist C:\agentC3SL rmdir C:\agentC3SL /s /q
- agent-1234.exe /SILENT /VERYSILENT
- if not exist C:\agentC3SL exit 1;
- copy C:\jq-win32.exe .\test
- cd .\test
- C:\agentC3SL\bin\agent-v0.0.exe --once --print > test.json
- testWin.bat
- C:\agentC3SL\uninstall_agent.exe /SILENT /VERYSILENT
- dir /b /a "C:\agentC3SL\*" | >nul findstr "^" && (echo Agent has been uninstalled) || (exit 1);
dependencies:
- compileWin
# Optamos por remover os testes do windows, pois não conseguimos criar o runner, visto que sua
# criação iriam ter um impacto negativo em todos os demais runners.
# Caso se deseje testar o programa pelo windows existe o script test/testWin.bat, que ira realizar os testes,
# no ambiente windows.
......@@ -6,23 +6,34 @@ project( simmc-agent )
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# determines the thread library of the system
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# cpr requires c++11
#
if(WIN32)
add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_LIBS ON)
add_definitions(-DCURL_STATICLIB)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_WIN32_WINNT=0x0501)
# add_compile_options("/std:c++11")
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11)
add_definitions(-D_WIN32_WINNT=0x0501)
set(CMAKE_USE_WIN32_THREADS_INIT 1)
set(Threads_FOUND TRUE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -lwinpthread -static-libstdc++ -static-libgcc")
else()
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lpthread " )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif()
# src : main, collect functions + jsoncpp library
file ( GLOB SOURCES src/agent/*.cpp )
# src : curl requests
# options for cpr
......@@ -54,11 +65,14 @@ include ( "modules/boost.cmake" )
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB} ${PROGRAM_OPTIONS_LIB} ${CROSS_STATIC} )
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB} ${PROGRAM_OPTIONS_LIB} ${CROSS_STATIC} ${CMAKE_THREAD_LIBS_INIT})
add_dependencies ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} Boost )
add_dependencies ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
if ( UNIX )
# libudev
target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
endif ()
......@@ -11,7 +11,7 @@ Using *Linux* as default
- c++ compiler
- cmake
- libudev
- make-self
- makeself
<a name="HeaderBuildingAndCompiling"></a>
......
......@@ -3,5 +3,9 @@
"project" : "%s",
"proxyConf" : "%s",
"version" : "%s",
"webService" : "%s"
}
\ No newline at end of file
"webService" : "%s",
"agent_send_inventory": "%s",
"agent_send_net_band" : "%s",
"agent_send_user_hist": "%s",
"agent_send_database" : "%s"
}
......@@ -159,7 +159,7 @@ procedure change_config_file();
var
key, value : string;
begin
key := '{#idp},conf/proxy-conf.json,{#ws},{#version},{#prj}';
key := '{#idp},{#prj},conf/proxy-conf.json,{#version},{#ws}';
value := '%d,%s,%s,%s,%s';
read_file(WizardDirValue() + '\conf\datasid-conf.json', key, value);
end;
......
......@@ -31,6 +31,11 @@ usr=""
passwd=""
destination="./"
project="simmc"
asi="true" #agent_send_inventory
asnb="true" #agent_send_net_band
asuh="true" #agent_send_user_hist
asd="false" #agent_send_database
dir=$(dirname $0)
cd $dir
......@@ -47,9 +52,13 @@ for i in $@; do
;;
-h|--help)
echo "Usage: ";echo "generate agent.run with the desired setup";echo "options:"
echo " -idp=N: set idpoint as N";echo" -ws=s: set webService as s "
echo " -idp=N: set idpoint as N";echo " -ws=s: set webService as s "
echo " -pch=s: set proxyConf host as s";echo " -pcp=s: set proxyConf port as s"
echo " -pcu=s: set proxyConf user as s";echo " -pcpssd=s: set proxyConf password as s"
echo " -ver=s: set version as s";echo " -prj=s: set project name"
echo " -asi=true|false: set agent_send_inventory as true or false";echo " -asnb=true|false: set agent_send_net_band as true or false"
echo " -asuh=true|false: set agent_send_user_hist as true or false";echo " -asd=true|falses: set agent_send_database as true or false"
echo " -dest=d:set the agent directory as d"
echo " -h or --help: show this message"
exit 1
;;
......@@ -81,6 +90,22 @@ for i in $@; do
project="${i#*=}"
shift
;;
-asi=*)
asi="${i#*=}"
shift
;;
-asnb=*)
asnb="${i#*=}"
shift
;;
-asuh=*)
asuh="${i#*=}"
shift
;;
-asd=*)
asd="${i#*=}"
shift
;;
*)
echo "wrong usage\ntry -h or --help for help"
exit 1
......@@ -94,15 +119,13 @@ cp bin/agent-v0.0 $idPoint/agentC3SL/
mkdir $idPoint/agentC3SL/conf
cd $idPoint/agentC3SL/conf
touch datasid-conf.json
touch proxy.json
touch proxy-conf.json
tmp=$(cat ../../../conf/proxy-conf.json)
printf "$tmp\n" $host $port $usr $passwd > proxy.json
printf "$tmp\n" "$host" "$port" "$usr" "$passwd" > proxy-conf.json
tmp=$(cat ../../../conf/datasid-conf.json)
printf "$tmp\n" $idPoint $project conf/proxy-conf.json $version $webService > datasid-conf.json
printf "$tmp\n" "$idPoint" "$project" "conf/proxy-conf.json" "$version" "$webService" "$asi" "$asnb" "$asuh" "$asd" > datasid-conf.json
cd ../../..
......
......@@ -16,7 +16,7 @@
#include <agent/get_user_count.h>
#include <json/json.h>
/**
/**
* @file inventory.h
* @brief Collect all info from hardware, like processor, memory, mac adress, disks, machine type, os distro and so on.
* - The data collected are saved in a json object:
......@@ -34,4 +34,4 @@
* - Mac address
*/
Json::Value get_inventory(Agent*);
\ No newline at end of file
Json::Value get_inventory(Agent*);
......@@ -31,13 +31,13 @@ namespace fs = boost::filesystem;
std::string path_to_agent = "/opt/agentC3SL/"; // NOLINT(runtime/string)
//std::string path_to_agent_conf = // NOLINT(runtime/string)
//"/opt/agentC3SL/conf/"; // NOLINT(runtime/string)
std::string path_to_agent_conf = "/home/teste/Imagens/agent/conf/";
std::string path_to_agent_conf = "/opt/agentC3SL//conf/";
#else
// Temporary... Define agent path
std::string path_to_agent_tmp = "C:\\agentC3SL\\tmp\\";
std::string path_to_agent = "C:\\agentC3SL\\";
std::string path_to_agent_conf = // NOLINT(runtime/string)
"C:\\agentC3SL\\teste\\"; // NOLINT(runtime/string)
"C:\\agentC3SL\\conf\\"; // NOLINT(runtime/string)
#endif
bool agent_send_inventory = false;
......
......@@ -9,6 +9,7 @@
#include <agent/get_time.h>
#include <agent/helper.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <agent/agent.h>
/**
* @file network_bandwidth.h
......@@ -27,4 +28,4 @@
*/
std::string get_cutted_line(std::string, int);
Json::Value get_net_bandwidth();
Json::Value get_net_bandwidth(Agent*);
......@@ -20,17 +20,18 @@
# USA.
cd ..
mkdir tmp
cd tmp
temp_dir=$(mktemp -d)
if test -d /opt/agentC3SL; then
cp /opt/agentC3SL/conf/* . && rm ../agentC3SL/conf/* && mv ./* ../agentC3SL/conf/
cp /opt/agentC3SL/conf/* "$temp_dir" && rm conf/* && mv "$temp_dir"/* conf/
fi
cd ..
rm -rf tmp
rm -rf "$temp_dir"
rm -rf /opt/agentC3SL
cp -r agentC3SL /opt/
cd ..
mv agentC3SL /opt/
cd /opt/agentC3SL
if ! (crontab -l | grep -q agentC3SL) ;then
......
......@@ -6,7 +6,6 @@ SET ( CMAKE_C_COMPILER i686-w64-mingw32-gcc-posix )
SET ( CMAKE_CXX_COMPILER i686-w64-mingw32-g++-posix )
SET ( CMAKE_RC_COMPILER i686-w64-mingw32-windres )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32" )
SET ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -lwinpthread" )
SET ( CROSS_STATIC "iphlpapi" )
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32 )
......
......@@ -6,9 +6,7 @@ SET ( CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix )
SET ( CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix )
SET ( CMAKE_RC_COMPILER x86_64-w64-mingw32-windres )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32" )
SET ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -lwinpthread" )
SET ( CROSS_STATIC "iphlpapi" )
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 )
# adjust the default behaviour of the FIND_XXX() commands:
......
......@@ -28,8 +28,6 @@ if (NOT 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
......@@ -42,8 +40,6 @@ if (NOT 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
UPDATE_COMMAND ./bootstrap.sh --without-icu --with-libraries=filesystem,system,regex,program_options --includedir=${CMAKE_BINARY_DIR}/include/ && ${CMAKE_BINARY_DIR}/../configure_boost_crosscompile.sh ${CMAKE_CXX_COMPILER}
CONFIGURE_COMMAND ./b2 headers
......@@ -57,8 +53,6 @@ if (NOT 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
UPDATE_COMMAND ./bootstrap.bat --with-toolset=msvc-14.1 --with-libraries=filesystem,system,regex,program_options,chrono
CONFIGURE_COMMAND ./b2 headers
......
......@@ -81,25 +81,24 @@ void config_agent() {
std::ifstream agent_conf;
agent_conf.open(path_to_agent_conf + "datasid-conf.json",
std::ifstream::binary);
if (agent_conf.fail()) {
/* Nao conseguiu abrir o arquivo de configuracao.
Provavelmente está é um teste de desenvolvedor.
Assumindo que o projeto é o simmc.
*/
agent_send_inventory = true;
agent_send_net_band = true;
agent_send_user_hist = true;
}
reader.parse(agent_conf, conf, false);
if (conf["project"].compare("simmc") == 0) {
agent_send_inventory = true;
agent_send_net_band = true;
agent_send_user_hist = true;
} else if (conf["project"].compare("pinsis") == 0) {
agent_send_database = true;
}
}
if (!agent_conf.fail()) {
reader.parse(agent_conf, conf, false);
if (conf["agent_send_inventory"].compare("true") == 0) {
agent_send_inventory = true;
}
if (conf["agent_send_net_band"].compare("true") == 0) {
agent_send_net_band = true;
}
if (conf["agent_send_user_hist"].compare("true") == 0) {
agent_send_user_hist = true;
}
if (conf["agent_send_database"].compare("true") == 0) {
agent_send_database = true;
}
}
}
/** Parse command line
* - Options:
* - Help - help message
......@@ -140,7 +139,7 @@ int parse_command_line(int ac, char* av[], int *increment, int *lim,
if (vm.count("uninstall")) {
// remove setup to run on boot
kill_agent(SIGTERM);
fs::remove_all(path_to_agent + "agentC3SL");
fs::remove_all(path_to_agent);
return (1);
}
#endif
......@@ -196,7 +195,7 @@ int main(int argc, char* argv[]) {
pt::ptime begin;
if (parse_command_line(argc, argv, &increment, &lim, &print, &dev)) {
return (1);
return (0);
}
/* Set agent prefix (agent folder) */
......@@ -211,8 +210,8 @@ int main(int argc, char* argv[]) {
config_agent();
set_begin(begin);
/* make parse from config files. Case if ok, then send
* web service base url to send inventory, net bandwidth
/* make parse from config files. Case if ok, then send
* web service base url to send inventory, net bandwidth
* and user history
*/
if (read_config_files(&agent)) {
......
......@@ -63,15 +63,13 @@ std::string get_cutted_line(std::string line, int column) {
}
/** Get network bandwidth */
Json::Value get_net_bandwidth() {
Json::Value get_net_bandwidth(Agent* agent) {
Json::Value net_band;
Json::Value conf;
Json::Value net_band_all_time;
Json::Reader reader;
std::ofstream ofs;
std::ifstream net_band_file(path_to_agent_tmp + "net_band.json",
std::ifstream::binary);
std::ifstream agent_conf;
pt::ptime time;
std::string str;
std::fstream time_file;
......@@ -192,10 +190,7 @@ Json::Value get_net_bandwidth() {
// get id_point and mac_address
net_band["data_net"]["mac_address"] = get_macaddr();
agent_conf.open(path_to_agent_conf + "datasid-conf.json",
std::ifstream::binary);
reader.parse(agent_conf, conf , false);
net_band["data_net"]["id_point"] = conf["idPoint"];
net_band["data_net"]["id_point"] = agent->getConf()->getIdPoint();
// final data
net_band["data_net"]["bytes_received"] = b_rec - b_rec_allt;
......
......@@ -100,8 +100,8 @@ bool parse_proxy_file(Agent* agent) {
}
}
// Case windows, proxy.json values will be equals " "
// Case linux, proxy.json values will be equals ""
// Case windows, proxy-conf.json values will be equals " "
// Case linux, proxy-conf.json values will be equals ""
#ifdef WIN32
std::string find = " ";
#else
......
......@@ -62,7 +62,7 @@ int send_inventory(bool print, Agent* agent) {
*/
int send_net_bandwidth(bool print, Agent* agent) {
std::string base_url = agent->getConf()->getWebService();
Json::Value net = get_net_bandwidth();
Json::Value net = get_net_bandwidth(agent);
Json::FastWriter fastWriter;
if (print == true) {
......
......@@ -64,22 +64,22 @@ function packets_transmitted() {
}
function password() {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.password')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.password')
[[ "$obj" == "123mudar" ]]
}
function user () {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.usr')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.usr')
[[ "$obj" == "ninguem" ]]
}
function port() {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.port')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.port')
[[ "$obj" -eq 6666 ]]
}
function host() {
obj=$(cat /opt/agentC3SL/conf/proxy.json | jq -r '.host')
obj=$(cat /opt/agentC3SL/conf/proxy-conf.json | jq -r '.host')
[[ "$obj" == "mumm" ]]
}
......
This diff is collapsed.
if exist C:\agentC3SL rmdir C:\agentC3SL /s /q
agent-32.exe /SILENT /VERYSILENT
if not exist C:\agentC3SL exit 1;
copy C:\jq-win32.exe .\test
cd .\test
C:\agentC3SL\bin\agent-v0.0.exe --once --print > test.json
testWin.bat
C:\agentC3SL\uninstall_agent.exe /SILENT /VERYSILENT
dir /b /a "C:\agentC3SL\*" | >nul findstr "^" && (echo Agent has been uninstalled) || (exit 1);