Commit 37cff58a authored by gillesdubois's avatar gillesdubois
Browse files

Add experimental changes, see changelog + disclamer for more infos

parent 82db80fa
This diff is collapsed.
This diff is collapsed.
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// Ipdiscover.h: interface for the CIpdiscover class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_IPDISCOVER_H__D6015530_B5EE_45F3_B92A_021A5894341A__INCLUDED_)
#define AFX_IPDISCOVER_H__D6015530_B5EE_45F3_B92A_021A5894341A__INCLUDED_
#pragma once
#define IPDISCOVER_MIN_LATENCY 10 //ms
#define IPDISCOVER_DEFAULT_LATENCY 100 //ms
#define NB_IP_MAX 65534
#define DEFAULT_PORT 80
#define MAX_THREADS 300
#define MAX_FASTIP_THREADS 800
#ifndef WIN32
#include <pthread.h>
#define THREAD_CC
#define THREAD_TYPE pthread_t
#define THREAD_CREATE(tid, entry, arg) pthread_create(&(tid), NULL, \
(entry), (arg))
#else
#include <windows.h>
#define THREAD_CC __cdecl
#define THREAD_TYPE DWORD
#define THREAD_CREATE(tid, entry, arg) do { _beginthread((entry), 0, (arg));\
(tid) = GetCurrentThreadId(); \
} while (0)
#endif /* WIN32 */
#include "CapacityAbstract.h"
#include <Afxmt.h>
class CCapIpdiscover : public CCapacityAbstract
{
public: // Methods
// Standard constructor.and destructor
CCapIpdiscover();
~CCapIpdiscover();
// overloaded CCapacity method to set ipdiscover parameters
void setPrologResp(CPrologResponse* pPrologResp);
// Launch the scan
BOOL scanLocalNetwork();
// set the lan to scan (can be used manually)
void setLocalNetwork( LPCTSTR);
// set the latency (can be used manually)
void setLatency( LPCTSTR);
// Speed up detection by decreasing the latency significantly
void setFastIp();
// Do not wait for the threads termination
void setNoWait();
// Get current IP address worker thread must scan
ULONG CCapIpdiscover::GetIpToScan();
// Return the network number
ULONG GetNetworkNumber();
// Indicates that a new host was found
void AddHostFound( LPCTSTR lpstrIP, LPCTSTR lpstrMac, LPCTSTR lpstrHostName);
// Report that there was an error for host
void ReportHostFailed( LPCTSTR lpstrMessage);
// Lock and unlock access to the object, to grant worker threads exclusive access when updating results
BOOL LockCriticalSection();
BOOL UnlockCriticalSection();
// Function SendARP of IPHLPAPI.DLL (available on Windows 98 or higher and NT4 SP4 or higher)
DWORD (WINAPI *lpfn_SendARP)(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen);
// Functions from Winsock2
u_long (WINAPI *lpfn_htonl)(u_long hostlong);
u_long (WINAPI *lpfn_ntohl)(u_long netlong);
unsigned long (WINAPI *lpfn_inet_addr)(const char* cp);
char* FAR (WINAPI *lpfn_inet_ntoa)(struct in_addr in);
private: // Attributes
ULONG m_ulIpToScan; // IP to scan
ULONG m_ulNetNumber; // Network scanned
CString m_csLan;
ULONG m_ulHostFound; // Number of hosts found
ULONG m_ulIpDisc_lat; // Latency between each thread
CString m_csLatency;
BOOL m_bFastIp; // Do not wait Latency
CCriticalSection m_cs; // To grant exclusive access
DWORD m_dwMaxWaitTime;
};
#endif // !defined(AFX_IPDISCOVER_H__D6015530_B5EE_45F3_B92A_021A5894341A__INCLUDED_)
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// Ipdiscover.h: interface for the CIpdiscover class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_IPDISCOVER_H__D6015530_B5EE_45F3_B92A_021A5894341A__INCLUDED_)
#define AFX_IPDISCOVER_H__D6015530_B5EE_45F3_B92A_021A5894341A__INCLUDED_
#pragma once
#define IPDISCOVER_MIN_LATENCY 10 //ms
#define IPDISCOVER_DEFAULT_LATENCY 100 //ms
#define NB_IP_MAX 65534
#define DEFAULT_PORT 80
#define MAX_THREADS 300
#define MAX_FASTIP_THREADS 800
#ifndef WIN32
#include <pthread.h>
#define THREAD_CC
#define THREAD_TYPE pthread_t
#define THREAD_CREATE(tid, entry, arg) pthread_create(&(tid), NULL, \
(entry), (arg))
#else
#include <windows.h>
#define THREAD_CC __cdecl
#define THREAD_TYPE DWORD
#define THREAD_CREATE(tid, entry, arg) do { _beginthread((entry), 0, (arg));\
(tid) = GetCurrentThreadId(); \
} while (0)
#endif /* WIN32 */
#include "CapacityAbstract.h"
#include <Afxmt.h>
#include <iostream>
#include <fstream>
class CCapIpdiscover : public CCapacityAbstract
{
public: // Methods
// Standard constructor.and destructor
CCapIpdiscover();
~CCapIpdiscover();
// overloaded CCapacity method to set ipdiscover parameters
void setPrologResp(CPrologResponse* pPrologResp);
// Launch the scan
BOOL scanLocalNetwork();
// set the lan to scan (can be used manually)
void setLocalNetwork( LPCTSTR);
// set the latency (can be used manually)
void setLatency( LPCTSTR);
// Speed up detection by decreasing the latency significantly
void setFastIp();
// Do not wait for the threads termination
void setNoWait();
// Get current IP address worker thread must scan
ULONG CCapIpdiscover::GetIpToScan();
// Return the network number
ULONG GetNetworkNumber();
// Indicates that a new host was found
void AddHostFound( LPCTSTR lpstrIP, LPCTSTR lpstrMac, LPCTSTR lpstrHostName);
// Report that there was an error for host
void ReportHostFailed( LPCTSTR lpstrMessage);
// Lock and unlock access to the object, to grant worker threads exclusive access when updating results
BOOL LockCriticalSection();
BOOL UnlockCriticalSection();
// Function SendARP of IPHLPAPI.DLL (available on Windows 98 or higher and NT4 SP4 or higher)
DWORD (WINAPI *lpfn_SendARP)(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen);
// Functions from Winsock2
u_long (WINAPI *lpfn_htonl)(u_long hostlong);
u_long (WINAPI *lpfn_ntohl)(u_long netlong);
unsigned long (WINAPI *lpfn_inet_addr)(const char* cp);
char* FAR (WINAPI *lpfn_inet_ntoa)(struct in_addr in);
private: // Attributes
ULONG m_ulIpToScan; // IP to scan
ULONG m_ulNetNumber; // Network scanned
CString m_csLan;
ULONG m_ulHostFound; // Number of hosts found
ULONG m_ulIpDisc_lat; // Latency between each thread
CString m_csLatency;
BOOL m_bFastIp; // Do not wait Latency
CCriticalSection m_cs; // To grant exclusive access
DWORD m_dwMaxWaitTime;
};
#endif // !defined(AFX_IPDISCOVER_H__D6015530_B5EE_45F3_B92A_021A5894341A__INCLUDED_)
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
#include "stdafx.h"
#include "CapacityAbstract.h"
#include "CapKeyFinder.h"
......@@ -69,26 +69,26 @@ BOOL CCapKeyFinder::decodeMicrosoftKey( LPBYTE lpData, UINT uLength, CString csK
return TRUE;
}
/***
*
* Retrieve the keys from registry
*
***/
BOOL CCapKeyFinder::retrieveKeys()
{
INT_PTR nIndex = 0;
CMapStringToStringArray *pQueryArray = NULL;
CMapStringToString *pQuery = NULL;
try
{
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "KEYFINDER => Searching for software Product Key"));
return TRUE;
}
catch (CException *pEx)
{
pEx->Delete();
m_pLogger->log( LOG_PRIORITY_ERROR, _T( "KEYFINDER => Unknown error while searching for Product Key %ld"), nIndex+1);
return FALSE;
}
/***
*
* Retrieve the keys from registry
*
***/
BOOL CCapKeyFinder::retrieveKeys()
{
INT_PTR nIndex = 0;
CMapStringToStringArray *pQueryArray = NULL;
CMapStringToString *pQuery = NULL;
try
{
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "KEYFINDER => Searching for software Product Key"));
return TRUE;
}
catch (CException *pEx)
{
pEx->Delete();
m_pLogger->log( LOG_PRIORITY_ERROR, _T( "KEYFINDER => Unknown error while searching for Product Key %ld"), nIndex+1);
return FALSE;
}
}
\ No newline at end of file
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// CapRegistry.cpp: implementation of the CCapRegistry class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CapRegistry.h"
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// CapRegistry.cpp: implementation of the CCapRegistry class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CapRegistry.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCapRegistry::CCapRegistry()
{
}
CCapRegistry::~CCapRegistry()
{
}
/***
*
* Retrieve the keys from registry
*
***/
BOOL CCapRegistry::retrieveKeys()
{
INT_PTR nIndex = 0;
CMapStringToStringArray *pQueryArray = NULL;
CMapStringToString *pQuery = NULL;
try
{
// Retrieve the CMapStringToString array (we have to delete it)
pQueryArray = m_pPrologResp->getRegistryParameters();
if ((pQueryArray == NULL) || pQueryArray->IsEmpty())
{
// No registry query defined
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "REGISTRY => No query asked by server"));
return TRUE;
}
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "REGISTRY => Executing query asked by server"));
for (nIndex=0; nIndex<pQueryArray->GetCount(); nIndex++)
{
CRegistry myRegistry;
CRegistryValue myObject;
CString csName,
csRegKey,
csRegValue,
csResult,
csRegTree;
int nRegTree;
pQuery = pQueryArray->GetAt( nIndex);
if ((pQuery == NULL) || pQuery->IsEmpty())
continue;
if (!pQuery->Lookup( _T( "REGTREE"),csRegTree))
csRegTree.Empty();
if (!pQuery->Lookup( _T( "VAL"),csRegValue))
csRegValue.Empty();
if (!pQuery->Lookup( _T( "REGKEY"),csRegKey))
csRegKey.Empty();
if (!pQuery->Lookup( _T( "NAME"),csName))
csName.Empty();
nRegTree = _ttoi( csRegTree );
if (csRegValue == REGISTRY_ALL_VALUES_OF_KEY)
{
// Get all values of a key
myRegistry.GetRegistryMultipleValues( csName, nRegTree, csRegKey, &(m_pInventory->m_RegistryList));
}
else
{
// Get single value
if (myRegistry.GetRegistryValue( nRegTree, csRegKey, csRegValue, csResult))
{
// Add result to list
myObject.Set( csName, csResult);
m_pInventory->m_RegistryList.AddTail( myObject);
}
}
}
delete pQueryArray;
pQueryArray = NULL;
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "REGISTRY => %d query successfully executed"), nIndex);
return TRUE;
}
catch (CException *pEx)
{
pEx->Delete();
if (pQueryArray)
delete pQueryArray;
m_pLogger->log( LOG_PRIORITY_ERROR, _T( "REGISTRY => Unknown error while executing query %d"), nIndex+1);
return FALSE;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCapRegistry::CCapRegistry()
{
}
CCapRegistry::~CCapRegistry()
{
}
/***
*
* Retrieve the keys from registry
*
***/
BOOL CCapRegistry::retrieveKeys()
{
INT_PTR nIndex = 0;
CMapStringToStringArray *pQueryArray = NULL;
CMapStringToString *pQuery = NULL;
try
{
// Retrieve the CMapStringToString array (we have to delete it)
pQueryArray = m_pPrologResp->getRegistryParameters();
if ((pQueryArray == NULL) || pQueryArray->IsEmpty())
{
// No registry query defined
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "REGISTRY => No query asked by server"));
return TRUE;
}
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "REGISTRY => Executing query asked by server"));
for (nIndex=0; nIndex<pQueryArray->GetCount(); nIndex++)
{
CRegistry myRegistry;
CRegistryValue myObject;
CString csName,
csRegKey,
csRegValue,
csResult,
csRegTree;
int nRegTree;
pQuery = pQueryArray->GetAt( nIndex);
if ((pQuery == NULL) || pQuery->IsEmpty())
continue;
if (!pQuery->Lookup( _T( "REGTREE"),csRegTree))
csRegTree.Empty();
if (!pQuery->Lookup( _T( "VAL"),csRegValue))
csRegValue.Empty();
if (!pQuery->Lookup( _T( "REGKEY"),csRegKey))
csRegKey.Empty();
if (!pQuery->Lookup( _T( "NAME"),csName))
csName.Empty();
nRegTree = _ttoi( csRegTree );
if (csRegValue == REGISTRY_ALL_VALUES_OF_KEY)
{
// Get all values of a key
myRegistry.GetRegistryMultipleValues( csName, nRegTree, csRegKey, &(m_pInventory->m_RegistryList));
}
else
{
// Get single value
if (myRegistry.GetRegistryValue( nRegTree, csRegKey, csRegValue, csResult))
{
// Add result to list
myObject.Set( csName, csResult);
m_pInventory->m_RegistryList.AddTail( myObject);
}
}
}
delete pQueryArray;
pQueryArray = NULL;
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "REGISTRY => %d query successfully executed"), nIndex);
return TRUE;
}
catch (CException *pEx)
{
pEx->Delete();
if (pQueryArray)
delete pQueryArray;
m_pLogger->log( LOG_PRIORITY_ERROR, _T( "REGISTRY => Unknown error while executing query %d"), nIndex+1);
return FALSE;
}
}
\ No newline at end of file
This diff is collapsed.
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2015 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// Snmp.h: interface for the Snmp class
//
//////////////////////////////////////////////////////////////////////
#pragma once
#ifndef WIN32
#include <pthread.h>
#define THREAD_CC
#define THREAD_TYPE pthread_t
#define THREAD_CREATE(tid, entry, arg) pthread_create(&(tid), NULL, \
(entry), (arg))
#else
#include <windows.h>
#define THREAD_CC __cdecl
#define THREAD_TYPE DWORD
#define THREAD_CREATE(tid, entry, arg) do { _beginthread((entry), 0, (arg));\
(tid) = GetCurrentThreadId(); \
} while (0)
#endif /* WIN32 */
#include "OCSInventory Front.h"
#include "CapacityAbstract.h"
#include "OCSInventory.h"
#include <Afxmt.h>
#include <string>
#include <iostream>
#include <fstream>
#include <stdio.h>
class CCapSnmp : public CCapacityAbstract
{
public: // Methods
// Standard constructor.and destructor
CCapSnmp();
~CCapSnmp();
BOOL CheckOid(CString Community, CString IP, CString Oid);
void PrinterModule(CString Community, CString IP, CMarkup *Xml);
void TraysModule(CString Community, CString IP, CMarkup *Xml);
void CartridgesModule(CString Community, CString IP, CMarkup *Xml);
CString PhysicalModule(CString Community, CString IP);
void ScanPhysicalModule(CString Community, CString IP, CMarkup *Xml, CString Name);
BOOL RetrieveCommunities();
// Call OcsSnmp
void CallSnmp(CConnexionAbstract *pConnexion, CConfig *m_pConfig);
// Call Custom mibs files in snmp directory
void CallCustomMibs(std::string IpAddr, std::string Community);
};
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// CapacityAbstract.cpp: implementation of the CCapacityAbstract class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ocsinventory.h"
#include "CapacityAbstract.h"
//====================================================================================
// Open Computer and Software Inventory Next Generation
// Copyright (C) 2010 OCS Inventory NG Team. All rights reserved.
// Web: http://www.ocsinventory-ng.org
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence V2 http://www.gnu.org/ or Licence.txt
//====================================================================================
// CapacityAbstract.cpp: implementation of the CCapacityAbstract class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ocsinventory.h"
#include "CapacityAbstract.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCapacityAbstract::CCapacityAbstract()
{
m_pLogger = getOcsLogger();
m_pProlog = NULL;
m_pPrologResp = NULL;
m_pInventory = NULL;
m_pInventoryResp = NULL;
}
CCapacityAbstract::~CCapacityAbstract()
{