mirror of
https://github.com/bjango/istatserverlinux.git
synced 2025-10-21 15:08:08 +00:00
Fixed issue with OpenSSL 1.1+ (#4)
Process monitoring changes for Open/Net/Dragonfly BSD Version bump to 3.02 (104)
This commit is contained in:
10
configure.ac
10
configure.ac
@@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.59])
|
||||
AC_INIT([istatserver], [3.01], [http://github.com/bjango/istatserverlinux/issues])
|
||||
AC_INIT([istatserver], [3.02], [http://github.com/bjango/istatserverlinux/issues])
|
||||
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
||||
AM_MAINTAINER_MODE
|
||||
AC_CANONICAL_HOST
|
||||
@@ -122,6 +122,14 @@ AC_CHECK_LIB([ssl],[SSL_library_init], [
|
||||
], [])
|
||||
], [])
|
||||
|
||||
AC_CHECK_LIB([ssl],[OPENSSL_init_ssl], [
|
||||
AC_CHECK_LIB([crypto],[X509_new], [
|
||||
AC_DEFINE_UNQUOTED([HAVE_OPENSSL],1,[Define is openssl is available])
|
||||
LIBS="$LIBS -lssl -lcrypto"
|
||||
use_tls=yes
|
||||
], [])
|
||||
], [])
|
||||
|
||||
if test x"$use_tls" = x"none" ; then
|
||||
AC_MSG_ERROR([openssl/crypto not found or does not support tlsv1. you may need to update openssl or install openssl-dev/libssl-dev or a similar package])
|
||||
fi
|
||||
|
@@ -95,7 +95,11 @@ void DatabaseItem::prepare(string sql, sqlite3 *db)
|
||||
|
||||
void DatabaseItem::finalize()
|
||||
{
|
||||
if(_statement == NULL)
|
||||
return;
|
||||
|
||||
sqlite3_finalize(_statement);
|
||||
_statement = NULL;
|
||||
}
|
||||
|
||||
int DatabaseItem::query()
|
||||
|
@@ -43,6 +43,37 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
string encodeForXml(string sSrc)
|
||||
{
|
||||
ostringstream sRet;
|
||||
|
||||
for( string::const_iterator iter = sSrc.begin(); iter!=sSrc.end(); iter++ )
|
||||
{
|
||||
unsigned char c = (unsigned char)*iter;
|
||||
|
||||
switch( c )
|
||||
{
|
||||
case '&': sRet << "&"; break;
|
||||
case '<': sRet << "<"; break;
|
||||
case '>': sRet << ">"; break;
|
||||
case '"': sRet << """; break;
|
||||
case '\'': sRet << "'"; break;
|
||||
|
||||
default:
|
||||
if ( c<32 || c>127 )
|
||||
{
|
||||
sRet << "&#" << (unsigned int)c << ";";
|
||||
}
|
||||
else
|
||||
{
|
||||
sRet << c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sRet.str();
|
||||
}
|
||||
|
||||
string isr_create_header()
|
||||
{
|
||||
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
||||
@@ -236,7 +267,7 @@ string isr_network_data(int index, long sampleID, StatsNetwork stats, vector<str
|
||||
break;
|
||||
}
|
||||
|
||||
output << "<item uuid=\"" << item.device << "\" samples=\"" << samples.size() << "\"";
|
||||
output << "<item uuid=\"" << encodeForXml(item.device) << "\" samples=\"" << samples.size() << "\"";
|
||||
if(index == 0)
|
||||
{
|
||||
string addresses = "";
|
||||
@@ -246,7 +277,7 @@ string isr_network_data(int index, long sampleID, StatsNetwork stats, vector<str
|
||||
addresses += ",";
|
||||
addresses += item.addresses[i];
|
||||
}
|
||||
output << " name=\"" << item.device << "\" ip=\"" << addresses << "\" d=\"" << item.last_down << "\" u=\"" << item.last_up << "\"";
|
||||
output << " name=\"" << encodeForXml(item.device) << "\" ip=\"" << encodeForXml(addresses) << "\" d=\"" << item.last_down << "\" u=\"" << item.last_up << "\"";
|
||||
}
|
||||
|
||||
output << ">";
|
||||
@@ -366,10 +397,10 @@ string isr_activity_data(int index, long sampleID, StatsActivity stats, vector<s
|
||||
break;
|
||||
}
|
||||
|
||||
output << "<item uuid=\"" << item.device << "\" samples=\"" << samples.size() << "\"";
|
||||
output << "<item uuid=\"" << encodeForXml(item.device) << "\" samples=\"" << samples.size() << "\"";
|
||||
if(index == 0)
|
||||
{
|
||||
output << " name=\"" << item.device << "\" r=\"" << item.last_r << "\" w=\"" << item.last_w << "\" rio=\"" << item.last_rIOPS << "\" wio=\"" << item.last_wIOPS << "\"";
|
||||
output << " name=\"" << encodeForXml(item.device) << "\" r=\"" << item.last_r << "\" w=\"" << item.last_w << "\" rio=\"" << item.last_rIOPS << "\" wio=\"" << item.last_wIOPS << "\"";
|
||||
if(item.mounts.size() > 0)
|
||||
{
|
||||
output << " mounts=\"";
|
||||
@@ -426,7 +457,7 @@ string isr_disk_data(int index, long sampleID, StatsDisks stats, vector<string>
|
||||
break;
|
||||
}
|
||||
|
||||
output << "<item bsd=\"" << item.key << "\" uuid=\"" << item.uuid << "\" name=\"" << item.displayName << "\" samples=\"" << samples.size() << "\">";
|
||||
output << "<item bsd=\"" << encodeForXml(item.key) << "\" uuid=\"" << item.uuid << "\" name=\"" << encodeForXml(item.displayName) << "\" samples=\"" << samples.size() << "\">";
|
||||
for(size_t i = 0;i < samples.size(); i++)
|
||||
{
|
||||
struct disk_data sample = samples[i];
|
||||
@@ -512,7 +543,7 @@ string isr_sensor_data(int index, long sampleID, StatsSensors stats, vector<stri
|
||||
break;
|
||||
}
|
||||
|
||||
output << "<item low=\"" << item.lowestValue << "\" high=\"" << item.highestValue << "\" uuid=\"" << item.key << "\" name=\"" << item.label << "\" type=\"" << item.kind << "\" samples=\"" << samples.size() << "\">";
|
||||
output << "<item low=\"" << item.lowestValue << "\" high=\"" << item.highestValue << "\" uuid=\"" << item.key << "\" name=\"" << encodeForXml(item.label) << "\" type=\"" << item.kind << "\" samples=\"" << samples.size() << "\">";
|
||||
for(size_t i = 0;i < samples.size(); i++)
|
||||
{
|
||||
struct sensor_data sample = samples[i];
|
||||
@@ -575,7 +606,7 @@ string isr_process_data(int index, long sampleID, StatsProcesses stats, vector<s
|
||||
|
||||
for (vector<process_info>::iterator cur = _history.begin(); cur != _history.end(); ++cur)
|
||||
{
|
||||
output << "<item key=\"" << cur->pid << "\" c=\"" << cur->cpu << "\" name=\"" << cur->name << "\"></item>";
|
||||
output << "<item key=\"" << cur->pid << "\" c=\"" << cur->cpu << "\" name=\"" << encodeForXml(string(cur->name)) << "\"></item>";
|
||||
count++;
|
||||
if(count == 20)
|
||||
break;
|
||||
@@ -590,7 +621,7 @@ string isr_process_data(int index, long sampleID, StatsProcesses stats, vector<s
|
||||
|
||||
for (vector<process_info>::iterator cur = _history.begin(); cur != _history.end(); ++cur)
|
||||
{
|
||||
output << "<item key=\"" << cur->pid << "\" m=\"" << cur->memory << "\" name=\"" << cur->name << "\"></item>";
|
||||
output << "<item key=\"" << cur->pid << "\" m=\"" << cur->memory << "\" name=\"" << encodeForXml(string(cur->name)) << "\"></item>";
|
||||
count++;
|
||||
if(count == 20)
|
||||
break;
|
||||
|
@@ -126,11 +126,13 @@ int Socket::listen()
|
||||
timeout.tv_sec = 10;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
if (setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
|
||||
if (setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
|
||||
cout << "setsockopt failed" << endl;
|
||||
}
|
||||
|
||||
if (setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0)
|
||||
if (setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0){
|
||||
cout << "setsockopt failed" << endl;
|
||||
}
|
||||
|
||||
sockaddr_in myAddress;
|
||||
|
||||
|
@@ -84,7 +84,7 @@ void Stats::close()
|
||||
#endif
|
||||
}
|
||||
|
||||
void Stats::startStats()
|
||||
void Stats::prepare()
|
||||
{
|
||||
#ifdef HAVE_LIBKSTAT
|
||||
if(NULL == (ksh = kstat_open()))
|
||||
@@ -101,7 +101,7 @@ void Stats::startStats()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBKVM
|
||||
#ifdef HAVE_LIBKVM
|
||||
kvm_t *kd;
|
||||
if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) != NULL)
|
||||
{
|
||||
@@ -115,8 +115,11 @@ void Stats::startStats()
|
||||
batteryStats.kd = kd;
|
||||
processStats.kd = kd;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Stats::startStats()
|
||||
{
|
||||
#ifdef USE_SQLITE
|
||||
if(historyEnabled == true)
|
||||
{
|
||||
|
@@ -62,6 +62,7 @@
|
||||
class Stats
|
||||
{
|
||||
public:
|
||||
void prepare();
|
||||
void start();
|
||||
void startStats();
|
||||
void update_system_stats();
|
||||
|
@@ -35,8 +35,8 @@
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SERVER_VERSION 3.00
|
||||
#define SERVER_BUILD 103
|
||||
#define SERVER_VERSION 3.02
|
||||
#define SERVER_BUILD 104
|
||||
#define PROTOCOL_VERSION 3
|
||||
#define HISTORY_SIZE 600
|
||||
|
||||
|
55
src/main.cpp
55
src/main.cpp
@@ -159,6 +159,31 @@ int main(int argc, char ** argv)
|
||||
|
||||
::pn_signalresponder = &signalresponder;
|
||||
|
||||
|
||||
// Prepare stats
|
||||
stats.historyEnabled = true;
|
||||
if(to_int(config.get("disable_history_storage", "0")) == 1)
|
||||
stats.historyEnabled = false;
|
||||
|
||||
stats.diskStats.useMountPaths = to_int(config.get("disk_mount_path_label", "0"));
|
||||
stats.diskStats.customNames = config.get_array("disk_rename_label");
|
||||
stats.diskStats.disableFiltering = to_int(config.get("disk_disable_filtering", "0"));
|
||||
|
||||
stats.debugLogging = false;
|
||||
stats.sampleID = 0;
|
||||
|
||||
bool debugSocket = false;
|
||||
bool debugStats = false;
|
||||
|
||||
if (arguments.is_set("debug"))
|
||||
debugStats = true;
|
||||
|
||||
if (arguments.is_set("debugsocket"))
|
||||
debugSocket = true;
|
||||
|
||||
stats.debugLogging = debugStats;
|
||||
stats.prepare();
|
||||
|
||||
// Create socket, pid file and put in background if desired
|
||||
unixdaemon.create(arg_d, cf_server_user, cf_server_group);
|
||||
|
||||
@@ -193,20 +218,6 @@ int main(int argc, char ** argv)
|
||||
signal(SIGTERM, handler);
|
||||
signal(SIGPIPE, handler);
|
||||
|
||||
stats.debugLogging = false;
|
||||
stats.sampleID = 0;
|
||||
|
||||
bool debugSocket = false;
|
||||
bool debugStats = false;
|
||||
|
||||
if (arguments.is_set("debug"))
|
||||
debugStats = true;
|
||||
|
||||
if (arguments.is_set("debugsocket"))
|
||||
debugSocket = true;
|
||||
|
||||
stats.debugLogging = debugStats;
|
||||
|
||||
listener._session = (long)get_current_time();
|
||||
listener._serverUUID = serverUUID;
|
||||
listener._sslEnabled = 1;
|
||||
@@ -233,13 +244,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
sockets += listener;
|
||||
|
||||
stats.historyEnabled = true;
|
||||
if(to_int(config.get("disable_history_storage", "0")) == 1)
|
||||
stats.historyEnabled = false;
|
||||
|
||||
stats.diskStats.useMountPaths = to_int(config.get("disk_mount_path_label", "0"));
|
||||
stats.diskStats.customNames = config.get_array("disk_rename_label");
|
||||
stats.diskStats.disableFiltering = to_int(config.get("disk_disable_filtering", "0"));
|
||||
stats.start();
|
||||
|
||||
while (1)
|
||||
@@ -304,7 +309,13 @@ SSL_CTX* InitServerCTX(void)
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
SSL_load_error_strings();
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
SSL_CTX *ctx = SSL_CTX_new(TLSv1_server_method());
|
||||
#else
|
||||
SSL_CTX *ctx = SSL_CTX_new(TLS_server_method());
|
||||
#endif
|
||||
|
||||
if ( ctx == NULL )
|
||||
{
|
||||
ERR_print_errors_fp(stdout);
|
||||
@@ -323,6 +334,7 @@ SSL_CTX* InitServerCTX(void)
|
||||
SSL_CTX_set_tmp_ecdh(ctx, ecdh);
|
||||
EC_KEY_free(ecdh);
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
DH *dh = get_dh2236();
|
||||
if (dh == NULL) {
|
||||
cout << "Failed to get DH params" << endl;
|
||||
@@ -331,10 +343,12 @@ SSL_CTX* InitServerCTX(void)
|
||||
}
|
||||
SSL_CTX_set_tmp_dh(ctx, dh);
|
||||
DH_free(dh);
|
||||
#endif
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
DH *get_dh2236()
|
||||
{
|
||||
static unsigned char dh2236_p[]={
|
||||
@@ -375,6 +389,7 @@ DH *get_dh2236()
|
||||
{ DH_free(dh); return(NULL); }
|
||||
return(dh);
|
||||
}
|
||||
#endif
|
||||
|
||||
void LoadCertificates(SSL_CTX* ctx, char* CertFile, char* KeyFile)
|
||||
{
|
||||
|
@@ -218,7 +218,7 @@ void StatsProcesses::update(long long sampleID, double totalTicks)
|
||||
#elif defined(PROCESSES_KVM_DRAGONFLY)
|
||||
p = kvm_getprocs(kd, KERN_PROC_ALL, sizeof(kinfo_proc), &n_processes);
|
||||
#else
|
||||
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
||||
p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < n_processes; i++) {
|
||||
@@ -227,7 +227,11 @@ void StatsProcesses::update(long long sampleID, double totalTicks)
|
||||
#elif defined(PROCESSES_KVM_OPENBSD) || defined(PROCESSES_KVM_NETBSD)
|
||||
if (!((p[i].p_flag & P_SYSTEM)) && p[i].p_comm != NULL) {
|
||||
#else
|
||||
if (!((p[i].ki_flag & P_SYSTEM)) && p[i].ki_comm != NULL) {
|
||||
if (p[i].ki_stat != 0) {
|
||||
#ifdef TDF_IDLETD
|
||||
if(p[i].ki_tdflags & TDF_IDLETD)
|
||||
continue;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PROCESSES_KVM_DRAGONFLY)
|
||||
|
@@ -223,6 +223,7 @@ void StatsSensors::init_dev_cpu()
|
||||
label << "CPU " << x;
|
||||
(*cur).label = label.str();
|
||||
(*cur).method = 2;
|
||||
(*cur).kind = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,6 +255,7 @@ void StatsSensors::init_acpi_thermal()
|
||||
label << "Thermal Zone " << x;
|
||||
(*cur).label = label.str();
|
||||
(*cur).method = 4;
|
||||
(*cur).kind = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,6 +316,7 @@ void StatsSensors::init_qnap()
|
||||
{
|
||||
(*cur).label = "Temperature";
|
||||
(*cur).method = 3;
|
||||
(*cur).kind = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user