From fe54812cd70955f47af4010cedcf26e7ff6b592a Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 22 Jul 2012 19:20:28 -0500 Subject: [PATCH] Add server index --- servers/auth_server_lin/src/auth_conn.cpp | 22 +++++++++++++++++++--- servers/auth_server_lin/src/auth_conn.h | 4 +++- servers/auth_server_lin/src/main.cpp | 7 +++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index e073e12..f3f3474 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "auth_conn.h" @@ -39,8 +40,8 @@ struct exit_exception { For every client that connects to the server, the server creates a new instance of this class. */ -AuthSocket::AuthSocket(int sock, TQObject *parent, const char *name) : - TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_bound(false), m_servActive(false), m_servState(0), m_servClientSocket(NULL), m_servClientTimeout(NULL), m_loopTimer(NULL), m_config(static_cast(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL), +AuthSocket::AuthSocket(int sock, int serverID, TQObject *parent, const char *name) : + TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_bound(false), m_serverID(serverID), m_servActive(false), m_servState(0), m_servClientSocket(NULL), m_servClientTimeout(NULL), m_loopTimer(NULL), m_config(static_cast(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL), m_databaseServicesCursor(NULL), m_databaseServiceTypesCursor(NULL), m_databasePermissionsCursor(NULL), m_databaseActivityCursor(NULL) { @@ -445,6 +446,7 @@ void AuthSocket::commandLoop() { buffer->setValue("username", m_authenticatedUserName); buffer->setValue("realmname", m_authenticatedRealmName); buffer->setValue("logontime", TQDateTime::currentDateTime().toTime_t()); + buffer->setValue("serverid", m_serverID); m_databaseActivityCursor->insert(); ds << TQString("OK"); @@ -578,6 +580,20 @@ AuthServer::AuthServer(TQObject* parent) : exit(1); } + m_serverID = 0; + KCmdLineArgs* const args = KCmdLineArgs::parsedArgs(); + if ((args) && (args->count() > 0)) { + m_serverID = TQString(args->arg(0)).toInt(); + } + + // Delete existing activity entries for this server ID + TQSqlCursor databaseActivityCursor("activity", TRUE, m_database); + databaseActivityCursor.select(TQString("serverid='%1'").arg(m_serverID)); + if (databaseActivityCursor.next()) { + databaseActivityCursor.primeDelete(); + databaseActivityCursor.del(true); + } + if ( !ok() ) { printf("[ERROR] Failed to bind to port 4004\n\r"); exit(1); @@ -675,7 +691,7 @@ void AuthServer::pingSQLServer() { } void AuthServer::newConnection(int socket) { - AuthSocket *s = new AuthSocket(socket, this); + AuthSocket *s = new AuthSocket(socket, m_serverID, this); s->m_remoteHost = s->peerAddress().toString(); printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii()); connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater())); diff --git a/servers/auth_server_lin/src/auth_conn.h b/servers/auth_server_lin/src/auth_conn.h index 61fc626..d1245be 100644 --- a/servers/auth_server_lin/src/auth_conn.h +++ b/servers/auth_server_lin/src/auth_conn.h @@ -46,7 +46,7 @@ class AuthSocket : public TDEKerberosServerSocket Q_OBJECT public: - AuthSocket(int sock, TQObject *parent=0, const char *name=0); + AuthSocket(int sock, int serverID, TQObject *parent=0, const char *name=0); ~AuthSocket(); public: @@ -67,6 +67,7 @@ class AuthSocket : public TDEKerberosServerSocket TQString m_remoteHost; int m_stationID; bool m_bound; + int m_serverID; bool m_servActive; int m_servState; @@ -113,6 +114,7 @@ class AuthServer : public TQServerSocket KSimpleConfig* m_config; TQSqlDatabase* m_database; TQTimer* m_sqlPingTimer; + int m_serverID; friend class AuthSocket; diff --git a/servers/auth_server_lin/src/main.cpp b/servers/auth_server_lin/src/main.cpp index b023cf6..a4b233a 100644 --- a/servers/auth_server_lin/src/main.cpp +++ b/servers/auth_server_lin/src/main.cpp @@ -39,6 +39,12 @@ #include "auth_conn.h" +static const KCmdLineOptions options[] = +{ + { "+[id]", I18N_NOOP( "Set server id to 'id'" ), 0 }, + { 0, 0, 0 } +}; + static const char description[] = I18N_NOOP("RemoteFPGA Kerberos Authentication Server"); static const char version[] = "v0.0.1"; @@ -50,6 +56,7 @@ int main(int argc, char *argv[]) "(c) 2012, Timothy Pearson"); aboutData.addAuthor("Timothy Pearson",0, "kb9vqf@pearsoncomputing.net"); KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions(options); KApplication::disableAutoDcopRegistration(); KApplication app(false, false);