Patch level :10.0
Files correlati : Ricompilazione Demo : [ ] Commento :server modificati da provare su win2008 git-svn-id: svn://10.65.10.50/trunk@19835 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
70aa19c90f
commit
45aab711c3
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "dongle.h"
|
#include "dongle.h"
|
||||||
|
|
||||||
|
#include <wx/hashset.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -28,36 +30,44 @@ TUserInfo::TUserInfo(const wxChar* user, const wxChar* host)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class TUserTable : public wxObject
|
WX_DECLARE_HASH_MAP( wxString, TUserInfo*, wxStringHash, wxStringEqual, TUsersHashMap );
|
||||||
|
|
||||||
|
class TUserTable : public TUsersHashMap
|
||||||
{
|
{
|
||||||
wxHashTable m_Hash;
|
protected:
|
||||||
|
wxString BuildKey(wxSocketBase& sock, const wxChar* user, int session) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TUserInfo* AddConnection(wxSocketBase& sock, const wxChar* user, int session);
|
TUserInfo* AddConnection(wxSocketBase& sock, const wxChar* user, int session);
|
||||||
TUserInfo* Find(wxSocketBase& sock, const wxChar* user, int session);
|
TUserInfo* Find(wxSocketBase& sock, const wxChar* user, int session);
|
||||||
void RemoveConnection(wxSocketBase& sock, const wxChar* user, int session);
|
void RemoveConnection(wxSocketBase& sock, const wxChar* user, int session);
|
||||||
void Kill(const wxChar* user);
|
void Kill(const wxChar* strUserAtHost);
|
||||||
void KillSession(wxSocketBase& sock, int session);
|
void KillSession(wxSocketBase& sock, int session);
|
||||||
|
|
||||||
size_t GetCount() const { return m_Hash.GetCount(); }
|
size_t GetCount() const { return size(); }
|
||||||
size_t GetLicenses();
|
size_t GetLicenses() const;
|
||||||
void BeginFind() { m_Hash.BeginFind(); }
|
|
||||||
TUserInfo* Next() { wxHashTable::Node* n = m_Hash.Next(); return n ? (TUserInfo*)n->GetData() : NULL; }
|
|
||||||
|
|
||||||
TUserTable(size_t size = 13);
|
TUserTable();
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t TUserTable::GetLicenses()
|
WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual, THostSet );
|
||||||
{
|
|
||||||
wxHashTable Hosts;
|
|
||||||
|
|
||||||
BeginFind();
|
|
||||||
for (TUserInfo* ui = Next(); ui; ui = Next())
|
|
||||||
if (Hosts.Get(ui->m_strHost) == NULL)
|
|
||||||
Hosts.Put(ui->m_strHost, ui);
|
|
||||||
|
|
||||||
return Hosts.GetCount();
|
size_t TUserTable::GetLicenses() const
|
||||||
|
{
|
||||||
|
THostSet hsHosts;
|
||||||
|
for( TUsersHashMap::const_iterator it = begin(); it != end(); ++it )
|
||||||
|
hsHosts.insert(it->first);
|
||||||
|
return hsHosts.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString TUserTable::BuildKey(wxSocketBase& sock, const wxChar* user, int session) const
|
||||||
|
{
|
||||||
|
wxIPV4address peer; sock.GetPeer(peer);
|
||||||
|
wxString host;
|
||||||
|
host.Printf("%s:%d", peer.Hostname().c_str(), session);
|
||||||
|
wxString strUserAtHost;
|
||||||
|
strUserAtHost.Printf("%s@%s", user, host.c_str());
|
||||||
|
return strUserAtHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
TUserInfo* TUserTable::AddConnection(wxSocketBase& sock, const wxChar* user, int session)
|
TUserInfo* TUserTable::AddConnection(wxSocketBase& sock, const wxChar* user, int session)
|
||||||
@ -65,11 +75,9 @@ TUserInfo* TUserTable::AddConnection(wxSocketBase& sock, const wxChar* user, int
|
|||||||
TUserInfo* ui = Find(sock, user, session);
|
TUserInfo* ui = Find(sock, user, session);
|
||||||
if (ui == NULL)
|
if (ui == NULL)
|
||||||
{
|
{
|
||||||
wxIPV4address peer; sock.GetPeer(peer);
|
const wxString strUserAtHost = BuildKey(sock, user, session);
|
||||||
wxString host;
|
ui = new TUserInfo(user, strUserAtHost.After('@'));
|
||||||
host.Printf("%s:%d", (const char *) peer.Hostname(), session);
|
(*this)[strUserAtHost] = ui;
|
||||||
ui = new TUserInfo(user, host);
|
|
||||||
m_Hash.Put(wxString::Format("%s@%s", (const char *) user, host.c_str()), ui);
|
|
||||||
}
|
}
|
||||||
ui->m_nPrograms++;
|
ui->m_nPrograms++;
|
||||||
|
|
||||||
@ -78,18 +86,15 @@ TUserInfo* TUserTable::AddConnection(wxSocketBase& sock, const wxChar* user, int
|
|||||||
|
|
||||||
TUserInfo* TUserTable::Find(wxSocketBase& sock, const wxChar* user, int session)
|
TUserInfo* TUserTable::Find(wxSocketBase& sock, const wxChar* user, int session)
|
||||||
{
|
{
|
||||||
wxIPV4address peer; sock.GetPeer(peer);
|
const wxString strUserAtHost = BuildKey(sock, user, session);
|
||||||
wxString host;
|
|
||||||
|
|
||||||
host = wxString::Format("%s:%d", (const char *) peer.Hostname(), session);
|
|
||||||
|
|
||||||
if (user && *user)
|
if (user && *user)
|
||||||
return (TUserInfo*)m_Hash.Get(wxString::Format("%s@%s", (const char *) user, host.c_str()));
|
return (*this)[strUserAtHost];
|
||||||
|
|
||||||
BeginFind();
|
const wxString strHost = strUserAtHost.After('@');
|
||||||
for (TUserInfo* ui = Next(); ui; ui = Next())
|
for( TUsersHashMap::iterator it = begin(); it != end(); ++it )
|
||||||
{
|
{
|
||||||
if (ui->m_strHost == host)
|
TUserInfo* ui = it->second;
|
||||||
|
if (ui->m_strHost == strHost)
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,21 +108,16 @@ void TUserTable::RemoveConnection(wxSocketBase& sock, const wxChar* user, int se
|
|||||||
{
|
{
|
||||||
ui->m_nPrograms--;
|
ui->m_nPrograms--;
|
||||||
if (ui->m_nPrograms <= 0)
|
if (ui->m_nPrograms <= 0)
|
||||||
m_Hash.Delete(wxString::Format("%s@%s", ui->m_strName.c_str(), ui->m_strHost.c_str()));
|
{
|
||||||
|
const wxString strUserAtHost = BuildKey(sock, user, session);
|
||||||
|
erase(strUserAtHost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TUserTable::Kill(const wxChar* strUser)
|
void TUserTable::Kill(const wxChar* strUserAtHost)
|
||||||
{
|
{
|
||||||
BeginFind();
|
erase(strUserAtHost);
|
||||||
for (TUserInfo* ui = Next(); ui; ui = Next())
|
|
||||||
{
|
|
||||||
if (ui->m_strName == strUser)
|
|
||||||
{
|
|
||||||
m_Hash.Delete(wxString::Format("%s@%s", ui->m_strName.c_str(), ui->m_strHost.c_str()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TUserTable::KillSession(wxSocketBase& sock, int session)
|
void TUserTable::KillSession(wxSocketBase& sock, int session)
|
||||||
@ -126,15 +126,18 @@ void TUserTable::KillSession(wxSocketBase& sock, int session)
|
|||||||
{
|
{
|
||||||
TUserInfo* ui = Find(sock, NULL, session);
|
TUserInfo* ui = Find(sock, NULL, session);
|
||||||
if (ui != NULL)
|
if (ui != NULL)
|
||||||
m_Hash.Delete(wxString::Format("%s@%s", ui->m_strName.c_str(), ui->m_strHost.c_str()));
|
{
|
||||||
|
const wxString strUserAtHost = BuildKey(sock, ui->m_strName.c_str(), session);
|
||||||
|
erase(strUserAtHost);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TUserTable::TUserTable(size_t size) : m_Hash(wxKEY_STRING, size)
|
TUserTable::TUserTable()
|
||||||
{
|
{
|
||||||
m_Hash.DeleteContents(true);
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
@ -246,7 +249,7 @@ bool TAuthorizationServer::IsMagicName(wxString& strFilename) const
|
|||||||
strFilename = GetLogFileName();
|
strFilename = GetLogFileName();
|
||||||
} else
|
} else
|
||||||
if (strName == "activate" || strName == "deactivate" ||
|
if (strName == "activate" || strName == "deactivate" ||
|
||||||
strName == "year" || strName == "maxusers" || strName == "kill")
|
strName == "year" || strName == "maxusers" || strName == "kill.cgi")
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -425,10 +428,10 @@ void TAuthorizationServer::GenerateUsers(wxString& strFilename)
|
|||||||
th.AddChild("th").SetAttr("width", "15%") << "Date";
|
th.AddChild("th").SetAttr("width", "15%") << "Date";
|
||||||
th.AddChild("th").SetAttr("width", "15%") << "Kill";
|
th.AddChild("th").SetAttr("width", "15%") << "Kill";
|
||||||
|
|
||||||
m_Users.BeginFind();
|
|
||||||
int nUser = 0;
|
int nUser = 0;
|
||||||
for (TUserInfo* ui = m_Users.Next(); ui; ui = m_Users.Next())
|
for( TUsersHashMap::const_iterator it = m_Users.begin(); it != m_Users.end(); ++it )
|
||||||
{
|
{
|
||||||
|
const TUserInfo* ui = it->second;
|
||||||
TXmlItem& tr = table.AddChild("tr");
|
TXmlItem& tr = table.AddChild("tr");
|
||||||
tr.AddChild("td").SetAttr("align", "right") << wxString::Format("%d", ++nUser);
|
tr.AddChild("td").SetAttr("align", "right") << wxString::Format("%d", ++nUser);
|
||||||
tr.AddChild("td").AddChild("b") << ui->m_strName;
|
tr.AddChild("td").AddChild("b") << ui->m_strName;
|
||||||
@ -437,7 +440,8 @@ void TAuthorizationServer::GenerateUsers(wxString& strFilename)
|
|||||||
tr.AddChild("td").SetAttr("align", "center") << ui->m_time.Format("%H:%M:%S");
|
tr.AddChild("td").SetAttr("align", "center") << ui->m_time.Format("%H:%M:%S");
|
||||||
tr.AddChild("td").SetAttr("align", "center") << ui->m_time.Format("%d-%m-%Y");
|
tr.AddChild("td").SetAttr("align", "center") << ui->m_time.Format("%d-%m-%Y");
|
||||||
|
|
||||||
wxString href = wxString::Format("kill.cgi?%s", ui->m_strName.c_str());
|
wxString strKey; strKey << ui->m_strName << wxT("@") << ui->m_strHost;
|
||||||
|
wxString href = wxString::Format("kill.cgi?%s", strKey.c_str());
|
||||||
AddLinkButton(tr.AddChild("td"), "Kill", href).SetAttr("width", "100%");
|
AddLinkButton(tr.AddChild("td"), "Kill", href).SetAttr("width", "100%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -906,7 +910,13 @@ void TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
|
|||||||
if (cmd.StartsWith("DongleModules"))
|
if (cmd.StartsWith("DongleModules"))
|
||||||
{
|
{
|
||||||
outs.Write(m_Modules, sizeof(m_Modules));
|
outs.Write(m_Modules, sizeof(m_Modules));
|
||||||
}
|
} else
|
||||||
|
if (cmd.StartsWith("DongleLoggedLicenses"))
|
||||||
|
{
|
||||||
|
ReturnInt(outs, m_Users.GetLicenses());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING!
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ATOMIC_SEMAPHORE "DONGLE_SERVER_ATOM"
|
#define ATOMIC_SEMAPHORE "DONGLE_SERVER_ATOM"
|
||||||
|
@ -163,7 +163,11 @@ END_EVENT_TABLE()
|
|||||||
void TBaseServerApp::WriteLog(const wxChar* str) const
|
void TBaseServerApp::WriteLog(const wxChar* str) const
|
||||||
{
|
{
|
||||||
if (m_log != NULL)
|
if (m_log != NULL)
|
||||||
*m_log << str << endl;
|
{
|
||||||
|
//raccatta data ed ora
|
||||||
|
const wxString strNow = wxNow();
|
||||||
|
*m_log << strNow << " " << str << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString TBaseServerApp::GetTempFilename(const wxChar * ext)
|
wxString TBaseServerApp::GetTempFilename(const wxChar * ext)
|
||||||
@ -416,9 +420,10 @@ void TBaseServerApp::ProcessHttpGet(wxString cmd, wxSocketBase& sock)
|
|||||||
{
|
{
|
||||||
const int stop = cmd.Find(" HTTP");
|
const int stop = cmd.Find(" HTTP");
|
||||||
wxString str = cmd.Mid(4, stop-4).Trim();
|
wxString str = cmd.Mid(4, stop-4).Trim();
|
||||||
if (str == "/")
|
|
||||||
str += "index.htm";
|
if (str == "/")
|
||||||
wxString strFilename = GetDocumentRoot() + str;
|
str += "index.htm";
|
||||||
|
wxString strFilename = GetDocumentRoot() + str;
|
||||||
SendFile(strFilename, sock);
|
SendFile(strFilename, sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +455,9 @@ void TBaseServerApp::ProcessCommand(wxString cmd, wxSocketBase& outs)
|
|||||||
ProcessFormCommand(cmd, outs);
|
ProcessFormCommand(cmd, outs);
|
||||||
} else
|
} else
|
||||||
if (cmd.StartsWith("GET "))
|
if (cmd.StartsWith("GET "))
|
||||||
ProcessHttpGet(cmd, outs);
|
ProcessHttpGet(cmd, outs); else
|
||||||
|
if (cmd.StartsWith("PING"))
|
||||||
|
outs << "PONG\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TBaseServerApp::OnServerEvent(wxSocketEvent& e)
|
void TBaseServerApp::OnServerEvent(wxSocketEvent& e)
|
||||||
@ -534,7 +541,9 @@ void TBaseServerApp::OnIdle(wxIdleEvent& event)
|
|||||||
sock.SetNotify(wxSOCKET_LOST_FLAG);
|
sock.SetNotify(wxSOCKET_LOST_FLAG);
|
||||||
|
|
||||||
wxString & str = ((TCommand *) m_Sockets[0])->m_Command;
|
wxString & str = ((TCommand *) m_Sockets[0])->m_Command;
|
||||||
WriteLog(str);
|
//scrive sul log solo se chiacchierone!
|
||||||
|
if (m_bLogVerbose)
|
||||||
|
WriteLog(str);
|
||||||
|
|
||||||
if (CanProcessCommand(str, sock))
|
if (CanProcessCommand(str, sock))
|
||||||
{
|
{
|
||||||
@ -664,9 +673,15 @@ bool TBaseServerApp::OnInit()
|
|||||||
|
|
||||||
str = GetLogFileName();
|
str = GetLogFileName();
|
||||||
if (!str.IsEmpty())
|
if (!str.IsEmpty())
|
||||||
|
{
|
||||||
m_log = new wxFileOutputStream(str);
|
m_log = new wxFileOutputStream(str);
|
||||||
|
m_bLogVerbose = GetConfigBool("LogVerbose");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_log = NULL;
|
m_log = NULL;
|
||||||
|
m_bLogVerbose = false;
|
||||||
|
}
|
||||||
|
|
||||||
m_nTmpCounter = 0;
|
m_nTmpCounter = 0;
|
||||||
|
|
||||||
@ -711,6 +726,8 @@ int TBaseServerApp::OnExit()
|
|||||||
Deinitialization();
|
Deinitialization();
|
||||||
delete m_SingleInstance;
|
delete m_SingleInstance;
|
||||||
delete m_server;
|
delete m_server;
|
||||||
|
m_SingleInstance = NULL;
|
||||||
|
m_server = NULL;
|
||||||
}
|
}
|
||||||
if (m_log != NULL)
|
if (m_log != NULL)
|
||||||
{
|
{
|
||||||
@ -718,6 +735,7 @@ int TBaseServerApp::OnExit()
|
|||||||
str << GetAppName() << " shutting down.";
|
str << GetAppName() << " shutting down.";
|
||||||
WriteLog(str);
|
WriteLog(str);
|
||||||
delete m_log;
|
delete m_log;
|
||||||
|
m_log = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -84,6 +84,7 @@ private:
|
|||||||
wxFileOutputStream* m_log;
|
wxFileOutputStream* m_log;
|
||||||
wxString m_strPath, m_strTempDir, m_strIni;
|
wxString m_strPath, m_strTempDir, m_strIni;
|
||||||
bool m_bRunning;
|
bool m_bRunning;
|
||||||
|
bool m_bLogVerbose;
|
||||||
int m_nTmpCounter;
|
int m_nTmpCounter;
|
||||||
wxArrayPtrVoid m_Sockets;
|
wxArrayPtrVoid m_Sockets;
|
||||||
|
|
||||||
|
@ -119,6 +119,9 @@ void TCoffeeServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
|
|||||||
|
|
||||||
SendFile(strFilename, outs);
|
SendFile(strFilename, outs);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
TBaseServerApp::ProcessCommand(cmd, outs); // Gestisce PING!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Istanziare l'applicazione principale
|
// Istanziare l'applicazione principale
|
||||||
|
199
server/lurch.cpp
199
server/lurch.cpp
@ -1,23 +1,61 @@
|
|||||||
#include "baseserv.h"
|
#include "baseserv.h"
|
||||||
|
|
||||||
#include <wx/config.h>
|
#include <wx/config.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
|
#include <wx/process.h>
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <wx/fileconf.h>
|
#include <wx/fileconf.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TProcess declaration
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class TLurchServer; //segnaposto della TLurchServer che serve alla TProcess
|
||||||
|
|
||||||
|
class TProcess : public wxProcess
|
||||||
|
{
|
||||||
|
TLurchServer* m_pLurch;
|
||||||
|
wxString m_strApp;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void OnTerminate(int pid, int status);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void ForcePid(int pid) { SetPid(pid); }
|
||||||
|
TProcess(TLurchServer* pLurch, const wxString& strApp) : m_pLurch(pLurch), m_strApp(strApp) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TLurchServer declaration
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//classe TProcessHashMap derivata da wxHashMap (è una specie di assocarray!)
|
||||||
|
WX_DECLARE_HASH_MAP( wxString, wxProcess*, wxStringHash, wxStringEqual, TProcessHashMap );
|
||||||
|
|
||||||
|
|
||||||
class TLurchServer : public TBaseServerApp
|
class TLurchServer : public TBaseServerApp
|
||||||
{
|
{
|
||||||
|
TProcessHashMap m_ProcMap;
|
||||||
|
wxTimer m_Timer;
|
||||||
|
int m_nFreq;
|
||||||
|
|
||||||
|
DECLARE_EVENT_TABLE();
|
||||||
protected:
|
protected:
|
||||||
virtual const wxChar* GetAppName() const;
|
virtual const wxChar* GetAppName() const;
|
||||||
virtual bool Initialization();
|
virtual bool Initialization();
|
||||||
|
void OnTimer(wxTimerEvent& evt);
|
||||||
|
|
||||||
void AddMiniForm(TXmlItem& tr, const wxChar* action, const wxChar* app, const wxChar* prompt) const;
|
void AddMiniForm(TXmlItem& tr, const wxChar* action, const wxChar* app, const wxChar* prompt) const;
|
||||||
void EnumerateVariables(const wxString& strApp, wxArrayString& arr) const;
|
void EnumerateVariables(const wxString& strApp, wxArrayString& arr) const;
|
||||||
|
|
||||||
void CreateServersList(wxArrayString& arr) const;
|
void CreateServersList(wxArrayString& arr) const;
|
||||||
|
bool PingProcess(const wxString& strApp);
|
||||||
|
void StopProcess(const wxString& strApp);
|
||||||
void KillProcess(const wxString& strApp);
|
void KillProcess(const wxString& strApp);
|
||||||
|
wxString StartProcess(const wxString& strApp);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void GenerateFile(wxString& strFilename);
|
void GenerateFile(wxString& strFilename);
|
||||||
@ -27,13 +65,79 @@ public:
|
|||||||
void ProcessHttpGet(wxString cmd, wxSocketBase& outs);
|
void ProcessHttpGet(wxString cmd, wxSocketBase& outs);
|
||||||
void ProcessHttpPost(wxString cmd, wxSocketBase& outs);
|
void ProcessHttpPost(wxString cmd, wxSocketBase& outs);
|
||||||
|
|
||||||
|
bool ForgetProcess(const wxString& strApp);
|
||||||
|
|
||||||
|
//metodi riguardanti l'interfaccia html
|
||||||
void ProcessFormStart(const THashTable& args, wxSocketBase& sock);
|
void ProcessFormStart(const THashTable& args, wxSocketBase& sock);
|
||||||
void ProcessFormKill(const THashTable& args, wxSocketBase& sock);
|
void ProcessFormStop(const THashTable& args, wxSocketBase& sock);
|
||||||
void ProcessFormConfig(const THashTable& args, wxSocketBase& sock);
|
void ProcessFormConfig(const THashTable& args, wxSocketBase& sock);
|
||||||
void ProcessFormUpdate(THashTable& args, wxSocketBase& sock);
|
void ProcessFormUpdate(THashTable& args, wxSocketBase& sock);
|
||||||
void CallCgi(wxString& strFileName, wxSocketBase& sock);
|
void CallCgi(wxString& strFileName, wxSocketBase& sock);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TProcess implementation
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void TProcess::OnTerminate(int pid, int WXUNUSED(status))
|
||||||
|
{
|
||||||
|
SetPid(pid);
|
||||||
|
m_pLurch->ForgetProcess(m_strApp);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// TLurchServer implementation
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(TLurchServer, TBaseServerApp)
|
||||||
|
EVT_TIMER(wxID_ANY, TLurchServer::OnTimer)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
bool TLurchServer::PingProcess(const wxString& strApp)
|
||||||
|
{
|
||||||
|
bool bPinged = false;
|
||||||
|
TProcess* pProcess = (TProcess*)m_ProcMap[strApp];
|
||||||
|
if (pProcess != NULL)
|
||||||
|
{
|
||||||
|
const wxString strPort = GetConfigString("Port", "", strApp);
|
||||||
|
if (!strPort.IsEmpty())
|
||||||
|
{
|
||||||
|
const int nTimeOut = m_nFreq > 3000 ? m_nFreq / 3000 : 1;
|
||||||
|
wxIPV4address ipAddress;
|
||||||
|
ipAddress.LocalHost();
|
||||||
|
ipAddress.Service(strPort);
|
||||||
|
wxSocketClient sSock(wxSOCKET_NOWAIT);
|
||||||
|
sSock.Connect(ipAddress, false);
|
||||||
|
if (sSock.WaitOnConnect(nTimeOut))
|
||||||
|
{
|
||||||
|
sSock.Write("PING\n", 5);
|
||||||
|
if (sSock.WaitForWrite(nTimeOut))
|
||||||
|
{
|
||||||
|
char buffer[8]; memset(buffer, 0, sizeof(buffer));
|
||||||
|
sSock.Read(buffer, 4);
|
||||||
|
if (sSock.WaitForRead(nTimeOut))
|
||||||
|
bPinged = wxStrcmp(buffer, "PONG") == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bPinged;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TLurchServer::OnTimer(wxTimerEvent& WXUNUSED(evt))
|
||||||
|
{
|
||||||
|
m_Timer.Stop();
|
||||||
|
const wxString strApp = "Authorization";
|
||||||
|
if (!PingProcess(strApp))
|
||||||
|
{
|
||||||
|
TProcess* pProcess = (TProcess*)m_ProcMap[strApp];
|
||||||
|
pProcess->Kill(pProcess->GetPid());
|
||||||
|
wxSleep(2);
|
||||||
|
StartProcess(strApp);
|
||||||
|
}
|
||||||
|
m_Timer.Start(m_nFreq);
|
||||||
|
}
|
||||||
|
|
||||||
const wxChar* TLurchServer::GetAppName() const
|
const wxChar* TLurchServer::GetAppName() const
|
||||||
{
|
{
|
||||||
return "Lurch";
|
return "Lurch";
|
||||||
@ -170,12 +274,13 @@ bool TLurchServer::IsCgiName(wxString strFilename) const
|
|||||||
return strExt == "cgi" || strExt == "exe";
|
return strExt == "cgi" || strExt == "exe";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TLurchServer::ProcessFormStart(const THashTable& args, wxSocketBase& sock)
|
|
||||||
{
|
|
||||||
bool ok = false;
|
|
||||||
|
|
||||||
const wxString strApp = args.Get("App");
|
wxString TLurchServer::StartProcess(const wxString& strApp)
|
||||||
if (!strApp.IsEmpty()) // Dummy test
|
{
|
||||||
|
bool ok = false;
|
||||||
|
|
||||||
|
wxString strMessage;
|
||||||
|
if (!strApp.IsEmpty())
|
||||||
{
|
{
|
||||||
const wxSingleInstanceChecker sic(strApp);
|
const wxSingleInstanceChecker sic(strApp);
|
||||||
ok = !sic.IsAnotherRunning();
|
ok = !sic.IsAnotherRunning();
|
||||||
@ -183,29 +288,61 @@ void TLurchServer::ProcessFormStart(const THashTable& args, wxSocketBase& sock)
|
|||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
wxString strRun = GetConfigString("Run", "", strApp);
|
const wxString strRun = GetConfigString("Run", "", strApp);
|
||||||
if (wxFileExists(strRun))
|
if (wxFileExists(strRun))
|
||||||
{
|
{
|
||||||
#ifdef LINUX
|
wxFileName fnPath;
|
||||||
if (strRun[ 0u] != '/' && strRun[ 0u] != '.')
|
fnPath.SetPath(GetServerPath());
|
||||||
strRun = "./" + strRun;
|
fnPath.SetFullName(strRun);
|
||||||
#endif
|
|
||||||
const long nProc = wxExecute(strRun);
|
TProcess* pProcess = new TProcess(this, strApp);
|
||||||
|
const long nProc = wxExecute(fnPath.GetFullPath(), wxEXEC_ASYNC, pProcess);
|
||||||
if (nProc == 0 || nProc == -1)
|
if (nProc == 0 || nProc == -1)
|
||||||
MessageBox("ERROR", wxString::Format("Can't run %s executable (%s)", strApp.c_str(),
|
{
|
||||||
strRun.c_str()), sock);
|
strMessage.Printf("Can't run %s executable (%s)", strApp.c_str(), strRun.c_str());
|
||||||
|
delete pProcess;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
MessageBox("Server Started", strApp, sock);
|
{
|
||||||
|
pProcess->ForcePid(nProc);
|
||||||
|
m_ProcMap[strApp] = pProcess; //memorizza il numero del processo che ha lanciato per poterlo usare in fase di controllo
|
||||||
|
strMessage = wxEmptyString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
MessageBox("ERROR", wxString::Format("Can't find %s executable (%s)", strApp.c_str(),
|
strMessage.Printf("Can't find %s executable (%s)", strApp.c_str(), strRun.c_str());
|
||||||
strRun.c_str()), sock);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
MessageBox("ERROR", wxString::Format("%s il already running", strApp.c_str()), sock);
|
strMessage.Printf("%s il already running", strApp.c_str());
|
||||||
|
|
||||||
|
if (strMessage.IsEmpty())
|
||||||
|
WriteLog(strApp + " started.");
|
||||||
|
else
|
||||||
|
WriteLog(strMessage);
|
||||||
|
|
||||||
|
return strMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TLurchServer::KillProcess(const wxString& strApp)
|
void TLurchServer::ProcessFormStart(const THashTable& args, wxSocketBase& sock)
|
||||||
|
{
|
||||||
|
const wxString strApp = args.Get("App");
|
||||||
|
if (!strApp.IsEmpty()) // Dummy test
|
||||||
|
{
|
||||||
|
const wxString strMessage = StartProcess(strApp);
|
||||||
|
if (strMessage.IsEmpty())
|
||||||
|
MessageBox("Server Started", strApp, sock);
|
||||||
|
else
|
||||||
|
MessageBox("ERROR", strMessage, sock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TLurchServer::ForgetProcess(const wxString& strApp)
|
||||||
|
{
|
||||||
|
WriteLog(strApp + " terminated.");
|
||||||
|
return m_ProcMap.erase(strApp) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TLurchServer::StopProcess(const wxString& strApp)
|
||||||
{
|
{
|
||||||
const wxString strHost = GetConfigString("Host", "localhost", strApp);
|
const wxString strHost = GetConfigString("Host", "localhost", strApp);
|
||||||
const int nPort = GetConfigInt("Port", 0, strApp);
|
const int nPort = GetConfigInt("Port", 0, strApp);
|
||||||
@ -225,12 +362,13 @@ void TLurchServer::KillProcess(const wxString& strApp)
|
|||||||
const wxSingleInstanceChecker sic(strApp);
|
const wxSingleInstanceChecker sic(strApp);
|
||||||
for (int i = 0; i < 5 && sic.IsAnotherRunning(); i++)
|
for (int i = 0; i < 5 && sic.IsAnotherRunning(); i++)
|
||||||
wxSleep(1);
|
wxSleep(1);
|
||||||
|
ForgetProcess(strApp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TLurchServer::ProcessFormKill(const THashTable& args, wxSocketBase& sock)
|
void TLurchServer::ProcessFormStop(const THashTable& args, wxSocketBase& sock)
|
||||||
{
|
{
|
||||||
const wxString strApp = args.Get("App");
|
const wxString strApp = args.Get("App");
|
||||||
if (strApp == GetAppName()) // Stop myself!
|
if (strApp == GetAppName()) // Stop myself!
|
||||||
@ -242,11 +380,11 @@ void TLurchServer::ProcessFormKill(const THashTable& args, wxSocketBase& sock)
|
|||||||
{
|
{
|
||||||
const wxSingleInstanceChecker sic(app[i]);
|
const wxSingleInstanceChecker sic(app[i]);
|
||||||
if (sic.IsAnotherRunning())
|
if (sic.IsAnotherRunning())
|
||||||
KillProcess(app[i]);
|
StopProcess(app[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KillProcess(strApp);
|
StopProcess(strApp);
|
||||||
MessageBox("Server stopped", strApp, sock);
|
MessageBox("Server stopped", strApp, sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +503,7 @@ void TLurchServer::CallCgi(wxString& strFileName, wxSocketBase& sock)
|
|||||||
if (strName == "start")
|
if (strName == "start")
|
||||||
ProcessFormStart(hashArgs, sock); else
|
ProcessFormStart(hashArgs, sock); else
|
||||||
if (strName == "kill")
|
if (strName == "kill")
|
||||||
ProcessFormKill(hashArgs, sock); else
|
ProcessFormStop(hashArgs, sock); else
|
||||||
if (strName == "config")
|
if (strName == "config")
|
||||||
ProcessFormConfig(hashArgs, sock); else
|
ProcessFormConfig(hashArgs, sock); else
|
||||||
if (strName == "update")
|
if (strName == "update")
|
||||||
@ -419,16 +557,13 @@ bool TLurchServer::Initialization()
|
|||||||
const wxString& strApp = arr[i];
|
const wxString& strApp = arr[i];
|
||||||
const bool bAutorun = GetConfigBool("Autorun", false, strApp);
|
const bool bAutorun = GetConfigBool("Autorun", false, strApp);
|
||||||
if (bAutorun)
|
if (bAutorun)
|
||||||
{
|
StartProcess(strApp);
|
||||||
const wxSingleInstanceChecker sic(strApp);
|
|
||||||
if (!sic.IsAnotherRunning())
|
|
||||||
{
|
|
||||||
wxString strRun = GetServerPath() + GetConfigString("Run", "", strApp);
|
|
||||||
if (wxFileExists(strRun))
|
|
||||||
wxExecute(strRun);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_nFreq = GetConfigInt("PingFreq") * 1000;
|
||||||
|
if (m_nFreq > 0)
|
||||||
|
m_Timer.Start(m_nFreq);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
[Authorization]
|
[Authorization]
|
||||||
Autorun=1
|
Autorun=1
|
||||||
Icon=autho.gif
|
Icon=autho.gif
|
||||||
LogFile=
|
LogFile=authoriz.txt
|
||||||
|
LogVerbose=
|
||||||
Run=authoriz.exe
|
Run=authoriz.exe
|
||||||
Port=1883
|
Port=1883
|
||||||
Donglehw=2
|
Donglehw=2
|
||||||
@ -16,6 +17,7 @@ Port=3885
|
|||||||
Icon=DataBase.gif
|
Icon=DataBase.gif
|
||||||
Run=DataBase.exe
|
Run=DataBase.exe
|
||||||
LogFile=
|
LogFile=
|
||||||
|
LogVerbose=
|
||||||
Dsn=
|
Dsn=
|
||||||
Query=
|
Query=
|
||||||
|
|
||||||
@ -25,15 +27,19 @@ Run=diction.exe
|
|||||||
Port=3883
|
Port=3883
|
||||||
Dictionary=english.xml
|
Dictionary=english.xml
|
||||||
LogFile=
|
LogFile=
|
||||||
|
LogVerbose=
|
||||||
|
|
||||||
[Postman]
|
[Postman]
|
||||||
Icon=postman.gif
|
Icon=postman.gif
|
||||||
Run=postman.exe
|
Run=postman.exe
|
||||||
Port=8080
|
Port=8080
|
||||||
LogFile=
|
LogFile=
|
||||||
|
LogVerbose=
|
||||||
|
|
||||||
[Lurch]
|
[Lurch]
|
||||||
Run=lurch.exe
|
Run=lurch.exe
|
||||||
Port=10000
|
Port=10000
|
||||||
Icon=lurch.gif
|
Icon=lurch.gif
|
||||||
LogFile=
|
LogFile=lurch.txt
|
||||||
|
LogVerbose=
|
||||||
|
PingFreq=10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user