Add server index

master
Timothy Pearson 12 years ago
parent 58cefd2d01
commit fe54812cd7

@ -25,6 +25,7 @@
#include <tqtimer.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#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<AuthServer*>(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<AuthServer*>(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()));

@ -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;

@ -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);

Loading…
Cancel
Save