Skip to content
Snippets Groups Projects
Commit 624290c3 authored by Lais Frigério's avatar Lais Frigério
Browse files

SCRUM#87 - Get distro info windows

parent 8cd169ed
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -5,3 +5,4 @@ test/docker/*/*.sh
log/*
styleguide/*
Documentation/*
.vs/*
......@@ -6,11 +6,17 @@ project( simmc-agent )
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
if(UNIX)
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
else(WIN32)
add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
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 )
......@@ -35,7 +41,7 @@ include_directories ( ${CURL_INCLUDE_DIRS} )
# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
add_subdirectory ( lib/dtwinver )
# add_subdirectory ( lib/dtwinver )
endif ()
# headers
......@@ -55,7 +61,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>
#include <sys/utsname.h>
#include <fstream>
#include <cpr/cpr.h>
#include <json/json.h>
......@@ -11,6 +10,10 @@
#include <agent/parse_proxy_file.h>
#include <agent/rotate_log_file.h>
#ifdef __linux__
#include <sys/utsname.h>
#endif
const std::string url = "http://localhost:3001";
/**
......
#pragma once
#include <libudev.h>
#include <iostream>
#include <fstream>
#include <list>
#include <string>
#ifdef __linux__
#include <libudev.h>
#endif
/**
* @file get_disks_info.h
* @brief Get 2 disks info (Model and size for each one)
......
#pragma once
#include <iostream>
#include <string>
#ifdef __linux__
#include <sys/utsname.h>
#else
#include <windows.h>
#include <lm.h>
#pragma comment(lib, "netapi32.lib")
#include <windows.h>
#include <VersionHelpers.h>
#endif
#include <agent/open_file.h>
/**
......
......@@ -4,37 +4,57 @@ 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)
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})
if(UNIX)
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 (FILESYSTEM_LIB ${BOOST_BUILD}/lib/libboost_filesystem-vc141-mt-1_65.lib)
SET (SYSTEM_LIB ${BOOST_BUILD}/lib/libboost_system-vc141-mt-1_65.lib)
SET (REGEX_LIB ${BOOST_BUILD}/lib/libboost_regex-vc141-mt-1_65.lib)
SET (PROGRAM_OPTIONS_LIB ${BOOST_BUILD}/lib/libboost_program_options-vc141-mt-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()
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
UPDATE_COMMAND ./bootstrap.bat --with-toolset=msvc-14.1 --with-libraries=filesystem,system,regex,program_options,chrono
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 -j8 link=static install --libdir=${CMAKE_BINARY_DIR}/lib toolset=msvc-14.1 --includedir=${CMAKE_BINARY_DIR}/include/boost
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/Boost/include/boost-1_65/boost ${CMAKE_BINARY_DIR}/include/boost
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,7 +61,12 @@ bool Curl::downloadAgent(std::string url, std::fstream* logFile,
agent->setRunName("agent.run");
boost::filesystem::path test_file(test_root / agent->getRunName());
FILE* fp = fopen(test_file.c_str(), "wb");
#ifdef WIN32
std::string var = test_file.string();
FILE* fp = fopen(var.c_str(), "wb");
#else
FILE* fp = fopen(test_file.c_str(), "wb");
#endif
if (!fp) {
agent->setMessage(__DATE__ + std::string(" - ERROR: Failed to ") +
......
......@@ -30,7 +30,11 @@ std::string get_date() {
char buffer[20];
time(&rawtime);
localtime_r(&rawtime, timeinfo);
#ifdef WIN32
timeinfo = localtime(&rawtime);
#else
localtime_r(&rawtime, timeinfo);
#endif
// YYYY-MM-DD
strftime(buffer, 20, "%Y-%m-%d", timeinfo);
......
......@@ -20,6 +20,7 @@
*/
#include <agent/get_disks_info.h>
#ifdef __linux__
/** We use here udev lib to get info about disks */
void get_scsi_disks(std::list<disk_t>& disks) { // NOLINT(runtime/references)
......@@ -109,7 +110,7 @@ void get_disks_info(std::list<disk_t>& disks) { // NOLINT(runtime/references)
throw std::string("No disk info found");
}
}
#endif
/**
* @file get_disks_info.cpp
* @brief Get 2 disks info (Model and size for each one)
......
......@@ -156,92 +156,30 @@ std::string get_distro() {
throw std::string("No release file found.");
#else
OSVERSIONINFOEX osver;
SYSTEM_INFO sysInfo;
typedef void(__stdcall *GETSYSTEMINFO) (LPSYSTEM_INFO);
__pragma(warning(push))
__pragma(warning(disable:4996))
memset(&osver, 0, sizeof(osver));
osver.dwOSVersionInfoSize = sizeof(osver);
GetVersionEx((LPOSVERSIONINFO)&osver);
__pragma(warning(pop))
DWORD major = 0;
DWORD minor = 0;
if (GetWinMajorMinorVersion(major, minor)) {
osver.dwMajorVersion = major;
osver.dwMinorVersion = minor;
} else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 2) {
OSVERSIONINFOEXW osvi;
ULONGLONG cm = 0;
cm = VerSetConditionMask(cm, VER_MINORVERSION, VER_EQUAL);
ZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
osvi.dwMinorVersion = 3;
if (VerifyVersionInfoW(&osvi, VER_MINORVERSION, cm)) {
osver.dwMinorVersion = 3;
}
}
GETSYSTEMINFO getSysInfo = (GETSYSTEMINFO)GetProcAddress(
GetModuleHandle(L"kernel32.dll"), "GetNativeSystemInfo");
if (getSysInfo == NULL)
getSysInfo = ::GetSystemInfo;
getSysInfo(&sysInfo);
if (osver.dwMajorVersion == 10 && osver.dwMinorVersion >= 0
&& osver.wProductType == VER_NT_WORKSTATION)
return "Windows 10";
if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 3
&& osver.wProductType == VER_NT_WORKSTATION)
return "Windows 8.1";
if (IsWindows10OrGreater())
return "Windows 10O";
if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 2
&& osver.wProductType == VER_NT_WORKSTATION)
return "Windows 8";
if (IsWindows8Point1OrGreater())
return "Windows 8.1";
if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1
&& osver.wProductType == VER_NT_WORKSTATION)
return "Windows 7";
if (IsWindows8OrGreater()
return "Windows 8";
if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0
&& osver.wProductType == VER_NT_WORKSTATION)
return "Windows Vista";
if (IsWindows7OrGreater())
return "Windows 7";
if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2
&& osver.wProductType == VER_NT_WORKSTATION &&
sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
return "Windows XP x64";
if (IsWindowsVistaOrGreater()
return "Windows Vista";
if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1)
return "Windows XP";
if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0)
return "Windows 2000";
if (IsWindowsXPOrGreater())
return "Windows XP";
throw std::string("unknown version");
#endif
}
#ifdef WIN32
bool GetWinMajorMinorVersion(DWORD& major, DWORD& minor) { // NOLINT [runtime/references]
bool bRetCode = false;
LPBYTE pinfoRawData = 0;
if (NERR_Success == NetWkstaGetInfo(NULL, 100, &pinfoRawData)) {
WKSTA_INFO_100* pworkstationInfo = (WKSTA_INFO_100*)pinfoRawData; // NOLINT [readability/casting]
major = pworkstationInfo->wki100_ver_major;
minor = pworkstationInfo->wki100_ver_minor;
::NetApiBufferFree(pinfoRawData);
bRetCode = true;
}
return bRetCode;
}
#endif
/**
* @file get_distro.cpp
* @brief Get distro info
......
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