summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--servers/auth_server_lin/src/auth_conn.cpp55
-rw-r--r--servers/auth_server_lin/src/auth_conn.h4
2 files changed, 56 insertions, 3 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp
index 2ed9860..42b6d2a 100644
--- a/servers/auth_server_lin/src/auth_conn.cpp
+++ b/servers/auth_server_lin/src/auth_conn.cpp
@@ -29,6 +29,11 @@
#include "auth_conn.h"
+#define STATISTICS_SERVER_START_EVENT 0
+#define STATISTICS_SERVER_STOP_EVENT 1
+#define STATISTICS_NEW_CONNECTION_EVENT 2
+#define STATISTICS_DISCONNECTION_EVENT 3
+
/* exception handling */
struct exit_exception {
int c;
@@ -42,7 +47,7 @@ struct exit_exception {
*/
AuthSocket::AuthSocket(int sock, int serverID, TQObject *parent, const char *name) :
TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_bound(false), m_serviceID(0), m_serverID(serverID), m_terminationStamp(0), m_servActive(false), m_servState(0), m_servClientSocket(NULL), m_servClientTimeout(NULL), m_loopTimer(NULL), m_pollTimer(NULL), m_config(static_cast<AuthServer*>(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL),
- m_databaseServicesCursor(NULL), m_databaseServiceTypesCursor(NULL), m_databasePermissionsCursor(NULL), m_databaseActivityCursor(NULL)
+ m_databaseServicesCursor(NULL), m_databaseServiceTypesCursor(NULL), m_databasePermissionsCursor(NULL), m_databaseActivityCursor(NULL), m_databaseStatisticsCursor(NULL)
{
// Initialize timers
@@ -96,6 +101,9 @@ AuthSocket::~AuthSocket() {
if (m_databaseActivityCursor) {
delete m_databaseActivityCursor;
}
+ if (m_databaseStatisticsCursor) {
+ delete m_databaseStatisticsCursor;
+ }
if (m_servClientSocket) {
delete m_servClientSocket;
}
@@ -111,6 +119,8 @@ void AuthSocket::close() {
void AuthSocket::connectionClosedHandler() {
printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii());
+ updateStatistics(STATISTICS_DISCONNECTION_EVENT);
+
// Update database
m_databaseActivityCursor->select(TQString("station='%1' AND username='%2' AND realmname='%3' AND serviceid=%4").arg(m_stationID).arg(m_authenticatedUserName).arg(m_authenticatedRealmName).arg(m_serviceID));
if (m_databaseActivityCursor->next()) {
@@ -330,7 +340,7 @@ int AuthSocket::servLoop() {
void AuthSocket::pollFlags() {
if ((m_bound) || (m_servActive)) {
- long long timestamp = TQDateTime::currentDateTime().toTime_t();
+ unsigned long long timestamp = TQDateTime::currentDateTime().toTime_t();
m_databaseActivityCursor->select(TQString("station='%1' AND username='%2' AND realmname='%3' AND serviceid=%4").arg(m_stationID).arg(m_authenticatedUserName).arg(m_authenticatedRealmName).arg(m_serviceID));
if (m_databaseActivityCursor->next()) {
m_terminationStamp = m_databaseActivityCursor->value("terminate").toLongLong();
@@ -346,6 +356,24 @@ void AuthSocket::pollFlags() {
m_pollTimer->start(1000, TRUE);
}
+void AuthSocket::updateStatistics(int eventType) {
+ // Update statistics
+ long long sessionID = -1;
+ m_databaseActivityCursor->select(TQString("station='%1' AND username='%2' AND realmname='%3' AND serverid='%4' AND serviceid='%5'").arg(m_stationID).arg(m_authenticatedUserName).arg(m_authenticatedRealmName).arg(m_serverID).arg(m_serviceID));
+ if (m_databaseActivityCursor->next()) {
+ sessionID = m_databaseActivityCursor->value("pk").toInt();
+ }
+ TQString userID = m_authenticatedUserName + "@" + m_authenticatedRealmName;
+ TQSqlRecord *buffer = m_databaseStatisticsCursor->primeInsert();
+ buffer->setValue("timestamp", TQDateTime::currentDateTime().toTime_t());
+ buffer->setValue("eventtypeid", eventType);
+ buffer->setValue("serverid", m_stationID);
+ buffer->setValue("sessionid", sessionID);
+ buffer->setValue("typeid", m_serviceID);
+ buffer->setValue("userid", userID);
+ m_databaseStatisticsCursor->insert();
+}
+
void AuthSocket::commandLoop() {
bool transferred_data;
@@ -464,6 +492,7 @@ void AuthSocket::commandLoop() {
}
else {
m_bound = true;
+ m_serviceID = 0;
// Update database
TQSqlRecord *buffer = m_databaseActivityCursor->primeInsert();
@@ -472,9 +501,11 @@ void AuthSocket::commandLoop() {
buffer->setValue("realmname", m_authenticatedRealmName);
buffer->setValue("logontime", TQDateTime::currentDateTime().toTime_t());
buffer->setValue("serverid", m_serverID);
- buffer->setValue("serviceid", 0);
+ buffer->setValue("serviceid", m_serviceID);
buffer->setValue("terminate", 0);
m_databaseActivityCursor->insert();
+
+ updateStatistics(STATISTICS_NEW_CONNECTION_EVENT);
ds << TQString("OK");
writeEndOfFrame();
@@ -536,6 +567,8 @@ void AuthSocket::commandLoop() {
buffer->setValue("terminate", 0);
m_databaseActivityCursor->insert();
+ updateStatistics(STATISTICS_NEW_CONNECTION_EVENT);
+
if (!m_servClientSocket) m_servClientSocket = new TDEKerberosClientSocket;
m_servClientSocket->setServiceName("remotefpga");
@@ -605,6 +638,7 @@ int AuthSocket::connectToDatabase() {
m_databaseServiceTypesCursor = new TQSqlCursor("servicetypes", TRUE, m_database);
m_databasePermissionsCursor = new TQSqlCursor("permissions", TRUE, m_database);
m_databaseActivityCursor = new TQSqlCursor("activity", TRUE, m_database);
+ m_databaseStatisticsCursor = new TQSqlCursor("statistics", TRUE, m_database);
return 0;
}
@@ -637,6 +671,13 @@ AuthServer::AuthServer(TQObject* parent) :
databaseActivityCursor.del(false);
}
+ // Update statistics
+ TQSqlCursor databaseStatisticsCursor("statistics", TRUE, m_database);
+ TQSqlRecord *buffer = databaseStatisticsCursor.primeInsert();
+ buffer->setValue("timestamp", TQDateTime::currentDateTime().toTime_t());
+ buffer->setValue("eventtypeid", STATISTICS_SERVER_START_EVENT);
+ databaseStatisticsCursor.insert();
+
if ( !ok() ) {
printf("[ERROR] Failed to bind to port 4004\n\r");
exit(1);
@@ -651,6 +692,14 @@ AuthServer::~AuthServer() {
delete m_sqlPingTimer;
m_sqlPingTimer = NULL;
}
+
+ // Update statistics
+ TQSqlCursor databaseStatisticsCursor("statistics", TRUE, m_database);
+ TQSqlRecord *buffer = databaseStatisticsCursor.primeInsert();
+ buffer->setValue("timestamp", TQDateTime::currentDateTime().toTime_t());
+ buffer->setValue("eventtypeid", STATISTICS_SERVER_STOP_EVENT);
+ databaseStatisticsCursor.insert();
+
if (m_database) {
TQSqlDatabase::removeDatabase(m_database);
m_database = NULL;
diff --git a/servers/auth_server_lin/src/auth_conn.h b/servers/auth_server_lin/src/auth_conn.h
index af816b9..b4f8b23 100644
--- a/servers/auth_server_lin/src/auth_conn.h
+++ b/servers/auth_server_lin/src/auth_conn.h
@@ -61,6 +61,9 @@ class AuthSocket : public TDEKerberosServerSocket
void commandLoop();
int servLoop();
void pollFlags();
+
+ private:
+ void updateStatistics(int eventType);
private:
int line;
@@ -91,6 +94,7 @@ class AuthSocket : public TDEKerberosServerSocket
TQSqlCursor* m_databaseServiceTypesCursor;
TQSqlCursor* m_databasePermissionsCursor;
TQSqlCursor* m_databaseActivityCursor;
+ TQSqlCursor* m_databaseStatisticsCursor;
StationList m_slist;