2004-03-25 10:35:14 +00:00
|
|
|
|
#include "baseserv.h"
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
2004-03-25 10:35:14 +00:00
|
|
|
|
#include "dongle.h"
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TUserInfo
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TUserInfo : public wxObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
wxString m_strName;
|
|
|
|
|
wxString m_strHost;
|
|
|
|
|
wxDateTime m_time;
|
|
|
|
|
size_t m_nPrograms;
|
|
|
|
|
|
|
|
|
|
TUserInfo(const wxChar* user, const wxChar* host);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TUserInfo::TUserInfo(const wxChar* user, const wxChar* host)
|
|
|
|
|
: m_strName(user), m_strHost(host),
|
|
|
|
|
m_time(wxDateTime::Now()), m_nPrograms(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TUserTable : public wxObject
|
|
|
|
|
{
|
|
|
|
|
wxHashTable m_Hash;
|
2004-04-01 08:42:27 +00:00
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2004-04-01 08:42:27 +00:00
|
|
|
|
TUserInfo* AddConnection(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);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
void Kill(const wxChar* user);
|
2005-05-16 23:44:23 +00:00
|
|
|
|
void KillSession(wxSocketBase& sock, int session);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
size_t GetCount() const { return m_Hash.GetCount(); }
|
2004-04-01 08:42:27 +00:00
|
|
|
|
size_t GetLicenses();
|
2002-10-24 10:47:49 +00:00
|
|
|
|
void BeginFind() { m_Hash.BeginFind(); }
|
2007-01-03 16:21:58 +00:00
|
|
|
|
TUserInfo* Next() { wxHashTable::Node* n = m_Hash.Next(); return n ? (TUserInfo*)n->GetData() : NULL; }
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
TUserTable(size_t size = 13);
|
|
|
|
|
};
|
|
|
|
|
|
2004-04-01 08:42:27 +00:00
|
|
|
|
size_t TUserTable::GetLicenses()
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
2004-04-01 08:42:27 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TUserInfo* TUserTable::AddConnection(wxSocketBase& sock, const wxChar* user, int session)
|
|
|
|
|
{
|
|
|
|
|
TUserInfo* ui = Find(sock, user, session);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
if (ui == NULL)
|
|
|
|
|
{
|
|
|
|
|
wxIPV4address peer; sock.GetPeer(peer);
|
2004-04-01 08:42:27 +00:00
|
|
|
|
wxString host;
|
|
|
|
|
|
|
|
|
|
host = wxString::Format("%s:%d", (const char *) peer.Hostname(), session);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
ui = new TUserInfo(user, host);
|
2004-03-25 10:35:14 +00:00
|
|
|
|
m_Hash.Put(wxString::Format("%s@%s", (const char *) user, host.c_str()), ui);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
ui->m_nPrograms++;
|
|
|
|
|
|
|
|
|
|
return ui;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-01 08:42:27 +00:00
|
|
|
|
TUserInfo* TUserTable::Find(wxSocketBase& sock, const wxChar* user, int session)
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
|
|
|
|
wxIPV4address peer; sock.GetPeer(peer);
|
2004-04-01 08:42:27 +00:00
|
|
|
|
wxString host;
|
|
|
|
|
|
|
|
|
|
host = wxString::Format("%s:%d", (const char *) peer.Hostname(), session);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
if (user && *user)
|
2004-03-25 10:35:14 +00:00
|
|
|
|
return (TUserInfo*)m_Hash.Get(wxString::Format("%s@%s", (const char *) user, host.c_str()));
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
BeginFind();
|
|
|
|
|
for (TUserInfo* ui = Next(); ui; ui = Next())
|
|
|
|
|
{
|
|
|
|
|
if (ui->m_strHost == host)
|
|
|
|
|
return ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-01 08:42:27 +00:00
|
|
|
|
void TUserTable::RemoveConnection(wxSocketBase& sock, const wxChar* user, int session)
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
2004-04-01 08:42:27 +00:00
|
|
|
|
TUserInfo* ui = Find(sock, user, session);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
if (ui)
|
|
|
|
|
{
|
|
|
|
|
ui->m_nPrograms--;
|
|
|
|
|
if (ui->m_nPrograms <= 0)
|
2004-03-25 10:35:14 +00:00
|
|
|
|
m_Hash.Delete(wxString::Format("%s@%s", ui->m_strName.c_str(), ui->m_strHost.c_str()));
|
2002-10-24 10:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TUserTable::Kill(const wxChar* strUser)
|
|
|
|
|
{
|
|
|
|
|
BeginFind();
|
|
|
|
|
for (TUserInfo* ui = Next(); ui; ui = Next())
|
|
|
|
|
{
|
|
|
|
|
if (ui->m_strName == strUser)
|
|
|
|
|
{
|
2004-03-25 10:35:14 +00:00
|
|
|
|
m_Hash.Delete(wxString::Format("%s@%s", ui->m_strName.c_str(), ui->m_strHost.c_str()));
|
2002-10-24 10:47:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-16 23:44:23 +00:00
|
|
|
|
void TUserTable::KillSession(wxSocketBase& sock, int session)
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
TUserInfo* ui = Find(sock, NULL, session);
|
|
|
|
|
if (ui != NULL)
|
|
|
|
|
m_Hash.Delete(wxString::Format("%s@%s", ui->m_strName.c_str(), ui->m_strHost.c_str()));
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
TUserTable::TUserTable(size_t size) : m_Hash(wxKEY_STRING, size)
|
|
|
|
|
{
|
|
|
|
|
m_Hash.DeleteContents(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TAuthorizationServer
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TAuthorizationServer : public TBaseServerApp
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
TDongle m_Dongle;
|
|
|
|
|
unsigned long m_Modules[3];
|
|
|
|
|
unsigned int m_nModules;
|
|
|
|
|
wxString m_strLastPassword;
|
2003-12-19 10:31:03 +00:00
|
|
|
|
wxString m_strLastApp;
|
|
|
|
|
unsigned int m_nPwdCount;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
TUserTable m_Users;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual const wxChar* GetAppName() const;
|
|
|
|
|
virtual void ProcessCommand(wxString cmd, wxSocketBase& outs);
|
|
|
|
|
|
|
|
|
|
void AddNumber(TXmlItem& tr, int n) const;
|
|
|
|
|
wxString DescribeModule(int m) const;
|
2003-12-05 12:11:57 +00:00
|
|
|
|
bool KeyIsGood(const wxString& key, const wxString& gar) const;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
void InitModules();
|
2002-12-20 17:08:30 +00:00
|
|
|
|
wxString GetModulesFilename() const;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
wxString Garble(unsigned short n, const wxDateTime& date) const;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool IsMagicName(wxString& strFilename) const;
|
|
|
|
|
|
|
|
|
|
void GenerateIndex(wxString& strFilename);
|
|
|
|
|
void GenerateUsers(wxString& strFilename);
|
|
|
|
|
void GenerateModules(wxString& strFilename);
|
|
|
|
|
void GenerateFile(wxString& strFile);
|
|
|
|
|
void ProcessFormCommand(wxString cmd, wxSocketBase& outs);
|
|
|
|
|
|
|
|
|
|
void ProcessActivation(int nModuble, bool act, wxSocketBase& outs);
|
|
|
|
|
void ReturnInt(wxSocketBase& outs, unsigned int i);
|
|
|
|
|
void ReturnBool(wxSocketBase&, bool b);
|
|
|
|
|
|
2003-12-19 10:31:03 +00:00
|
|
|
|
unsigned int DecodePassword(const wxChar* strPassword, const wxChar* strApp);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
void ProcessUserLogin(wxString cmd, wxSocketBase& sock);
|
|
|
|
|
bool ProcessUserLogout(wxString cmd, wxSocketBase& sock);
|
|
|
|
|
|
|
|
|
|
virtual bool Initialization();
|
|
|
|
|
virtual bool Deinitialization();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::InitModules()
|
|
|
|
|
{
|
|
|
|
|
m_nModules = 0;
|
|
|
|
|
memset(m_Modules, 0, sizeof(m_Modules));
|
|
|
|
|
m_Modules[0] = 2*sizeof(long);
|
|
|
|
|
if (m_Dongle.Ok())
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 48; i++)
|
|
|
|
|
{
|
|
|
|
|
if (m_Dongle.Active(i+1))
|
|
|
|
|
{
|
|
|
|
|
const size_t index = i / 32;
|
|
|
|
|
const unsigned long mask = 1 << (i & 31);
|
|
|
|
|
m_Modules[index+1] |= mask;
|
|
|
|
|
m_nModules++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxString TAuthorizationServer::Garble(unsigned short n, const wxDateTime& date) const
|
|
|
|
|
{
|
|
|
|
|
const long val = date2julian(date);
|
|
|
|
|
|
|
|
|
|
unsigned short data[4];
|
|
|
|
|
data[0] = m_Dongle.Number();
|
|
|
|
|
data[1] = n;
|
2004-03-25 10:35:14 +00:00
|
|
|
|
data[2] = (unsigned short)(val >> 16);
|
|
|
|
|
data[3] = (unsigned short)(val & 0xFFFF);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
m_Dongle.garble(data);
|
|
|
|
|
return wxString::Format("%04X%04X", data[0], data[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Implementare almeno queste due funzioni pure virtuali
|
|
|
|
|
|
|
|
|
|
const wxChar* TAuthorizationServer::GetAppName() const
|
|
|
|
|
{
|
|
|
|
|
return "Authorization";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAuthorizationServer::IsMagicName(wxString& strFilename) const
|
|
|
|
|
{
|
|
|
|
|
wxString strName;
|
|
|
|
|
wxSplitPath(strFilename, NULL, &strName, NULL);
|
|
|
|
|
strName.MakeLower();
|
|
|
|
|
const int q = strName.Find('?');
|
|
|
|
|
if (q > 0)
|
|
|
|
|
strName.Truncate(q);
|
|
|
|
|
|
|
|
|
|
if (strName == "index" || strName == "users" || strName == "modules")
|
|
|
|
|
{
|
|
|
|
|
strFilename = strName;
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "log")
|
|
|
|
|
{
|
|
|
|
|
strFilename = GetLogFileName();
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "activate" || strName == "deactivate" ||
|
|
|
|
|
strName == "year" || strName == "maxusers" || strName == "kill")
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
|
wxString TAuthorizationServer::GetModulesFilename() const
|
|
|
|
|
{
|
|
|
|
|
wxString strAut = "../campo.aut";
|
|
|
|
|
if (!wxFileExists(strAut))
|
|
|
|
|
strAut = "../prassi.aut";
|
|
|
|
|
return strAut;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
wxString TAuthorizationServer::DescribeModule(int m) const
|
|
|
|
|
{
|
2002-12-20 17:08:30 +00:00
|
|
|
|
const wxString strAut = GetModulesFilename();
|
|
|
|
|
wxFileInputStream aut(strAut);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
wxString line;
|
|
|
|
|
for (int nModule = 0; !aut.Eof(); nModule++)
|
|
|
|
|
{
|
|
|
|
|
aut >> line;
|
|
|
|
|
if (nModule == m)
|
|
|
|
|
return line.Mid(3);
|
|
|
|
|
}
|
|
|
|
|
return line; // Should never happen!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::AddNumber(TXmlItem& tr, int n) const
|
|
|
|
|
{
|
|
|
|
|
TXmlItem& td = tr.AddChild("td");
|
|
|
|
|
td.SetAttr("align", "right");
|
|
|
|
|
td << wxString::Format("%d", n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::GenerateIndex(wxString& strFilename)
|
|
|
|
|
{
|
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html);
|
|
|
|
|
|
|
|
|
|
TXmlItem& title = body.AddChild("h1").AddChild("center");
|
|
|
|
|
if (m_Dongle.Ok())
|
|
|
|
|
{
|
2002-12-20 17:08:30 +00:00
|
|
|
|
TXmlItem& tr = title.AddChild("table").SetAttr("width", "40%").AddChild("tr");
|
|
|
|
|
|
|
|
|
|
TXmlItem& td = tr.AddChild("td").SetAttr("width", "30%");
|
2002-10-24 10:47:49 +00:00
|
|
|
|
const bool hard = m_Dongle.hardware() == _dongle_hardlock;
|
2002-12-20 17:08:30 +00:00
|
|
|
|
TXmlItem& img = td.AddChild("img");
|
2002-10-24 10:47:49 +00:00
|
|
|
|
img.SetAttr("src", hard ? "hardlock.gif" : "eutron.gif");
|
2002-12-20 17:08:30 +00:00
|
|
|
|
|
|
|
|
|
tr.AddChild("td").SetAttr("align", "center").AddChild("h1") << (hard ? "Hardlock EYE" : "Eutron Smartkey");
|
2002-10-24 10:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
title << "No Dongle Connected!";
|
|
|
|
|
}
|
|
|
|
|
body.AddChild("br");
|
|
|
|
|
|
|
|
|
|
TXmlItem& table = body.AddChild("center").AddChild("table");
|
|
|
|
|
table.SetAttr("border", "1");
|
|
|
|
|
table.SetAttr("width", "70%");
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr0 = body.AddChild("tr");
|
|
|
|
|
tr0.AddChild("td") << "Serial Number";
|
|
|
|
|
AddNumber(tr0, m_Dongle.Number());
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr1 = body.AddChild("tr");
|
|
|
|
|
TXmlItem& ay = tr1.AddChild("td").AddChild("a");
|
2002-12-20 17:08:30 +00:00
|
|
|
|
ay.SetAttr("href", "year.htm") << "Assistance Year";
|
2002-10-24 10:47:49 +00:00
|
|
|
|
AddNumber(tr1, m_Dongle.YearAssist());
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr2 = body.AddChild("tr");
|
|
|
|
|
TXmlItem& mu = tr2.AddChild("td").AddChild("a");
|
2002-12-20 17:08:30 +00:00
|
|
|
|
mu.SetAttr("href", "maxusers.htm") << "Maximum Users";
|
2002-10-24 10:47:49 +00:00
|
|
|
|
AddNumber(tr2, m_Dongle.MaxUsers());
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr3 = body.AddChild("tr");
|
|
|
|
|
TXmlItem& au = tr3.AddChild("td").AddChild("a");
|
2002-12-20 17:08:30 +00:00
|
|
|
|
au.SetAttr("href", "Users.htm"); au << "Active Users";
|
2002-10-24 10:47:49 +00:00
|
|
|
|
AddNumber(tr3, m_Users.GetCount());
|
|
|
|
|
|
2004-04-01 08:42:27 +00:00
|
|
|
|
TXmlItem& tr3a = body.AddChild("tr");
|
|
|
|
|
TXmlItem& lu = tr3a.AddChild("td").AddChild("a");
|
|
|
|
|
lu << "Active Licenses";
|
|
|
|
|
AddNumber(tr3a, m_Users.GetLicenses());
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
TXmlItem& tr4 = body.AddChild("tr");
|
|
|
|
|
TXmlItem& am = tr4.AddChild("td").AddChild("a");
|
2002-12-20 17:08:30 +00:00
|
|
|
|
am.SetAttr("href", "Modules.htm"); am << "Active Modules";
|
2002-10-24 10:47:49 +00:00
|
|
|
|
AddNumber(tr4, m_nModules);
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr5 = body.AddChild("tr");
|
|
|
|
|
TXmlItem& al = tr5.AddChild("td").AddChild("a");
|
|
|
|
|
al.SetAttr("href", "Log"); al << "Log File";
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr6 = body.AddChild("tr");
|
|
|
|
|
TXmlItem& as = tr6.AddChild("td").AddChild("a");
|
|
|
|
|
as.SetAttr("href", "stop.cgi"); as << "Stop the Server";
|
2003-12-05 12:11:57 +00:00
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::GenerateModules(wxString& strFilename)
|
|
|
|
|
{
|
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html, "Modules");
|
|
|
|
|
TXmlItem& table = body.AddChild("table");
|
|
|
|
|
table.SetAttr("border", "1"); table.SetAttr("width", "100%");
|
|
|
|
|
|
|
|
|
|
TXmlItem& th = body.AddChild("thead");
|
|
|
|
|
th.AddChild("th").SetAttr("width", "7%") << "N.";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "8%") << "Module";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "70%") << "Description";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "De/Activate";
|
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
|
const wxString strAut = GetModulesFilename();
|
|
|
|
|
wxFileInputStream aut(strAut);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
for (int nModule = 0; !aut.Eof(); nModule++)
|
|
|
|
|
{
|
2003-12-05 12:11:57 +00:00
|
|
|
|
wxString line;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
aut >> line;
|
2003-12-05 12:11:57 +00:00
|
|
|
|
if (line.IsEmpty())
|
|
|
|
|
break;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
const wxString strCode = line.Left(2);
|
|
|
|
|
const wxString strDesc = line.Mid(3);
|
|
|
|
|
if (nModule > 0 && strCode != "xx" && !strDesc.IsEmpty())
|
|
|
|
|
{
|
2003-12-05 12:11:57 +00:00
|
|
|
|
const bool bOn = nModule == 0 || m_Dongle.Active(nModule);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
TXmlItem& tr = body.AddChild("tr");
|
|
|
|
|
AddNumber(tr, nModule);
|
|
|
|
|
tr.AddChild("td").SetAttr("align", "center") << strCode;
|
2003-12-05 12:11:57 +00:00
|
|
|
|
TXmlItem& td = tr.AddChild("td");
|
|
|
|
|
td.AddChild(bOn ? "b" : "i") << strDesc;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
if (nModule > 0)
|
|
|
|
|
{
|
2003-12-05 12:11:57 +00:00
|
|
|
|
const char* prompt = bOn ? "Deactivate" : "Activate";
|
2002-10-24 10:47:49 +00:00
|
|
|
|
const wxString href = wxString::Format("%s?%d", prompt, nModule);
|
|
|
|
|
TXmlItem& bu = AddLinkButton(tr.AddChild("td"), prompt, href);
|
|
|
|
|
bu.SetAttr("width", "100%");
|
|
|
|
|
bu.SetAttr("title", wxString::Format("Click to %s Module %d", prompt, nModule));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-05 12:11:57 +00:00
|
|
|
|
body.AddChild("br");
|
|
|
|
|
AddLinkButton(body.AddChild("center"), "Return to main page", "/");
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::GenerateUsers(wxString& strFilename)
|
|
|
|
|
{
|
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html, "Users");
|
|
|
|
|
|
|
|
|
|
TXmlItem& table = body.AddChild("table");
|
|
|
|
|
table.SetAttr("border", "1"); table.SetAttr("width", "100%");
|
|
|
|
|
|
|
|
|
|
TXmlItem& th = table.AddChild("thead");
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "N.";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "10%") << "User";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "Host";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "Programs";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "Time";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "Date";
|
|
|
|
|
th.AddChild("th").SetAttr("width", "15%") << "Kill";
|
|
|
|
|
|
|
|
|
|
m_Users.BeginFind();
|
|
|
|
|
int nUser = 0;
|
|
|
|
|
for (TUserInfo* ui = m_Users.Next(); ui; ui = m_Users.Next())
|
|
|
|
|
{
|
|
|
|
|
TXmlItem& tr = table.AddChild("tr");
|
|
|
|
|
tr.AddChild("td").SetAttr("align", "right") << wxString::Format("%d", ++nUser);
|
|
|
|
|
tr.AddChild("td").AddChild("b") << ui->m_strName;
|
|
|
|
|
tr.AddChild("td") << ui->m_strHost;
|
|
|
|
|
tr.AddChild("td").SetAttr("align", "right") << wxString::Format("%u", ui->m_nPrograms);
|
|
|
|
|
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");
|
|
|
|
|
|
2004-03-25 10:35:14 +00:00
|
|
|
|
wxString href = wxString::Format("kill.cgi?%s", ui->m_strName.c_str());
|
2002-10-24 10:47:49 +00:00
|
|
|
|
AddLinkButton(tr.AddChild("td"), "Kill", href).SetAttr("width", "100%");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body.AddChild("br");
|
2003-12-05 12:11:57 +00:00
|
|
|
|
AddLinkButton(body.AddChild("center"), "Return to main page", "/");
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::GenerateFile(wxString& strFilename)
|
|
|
|
|
{
|
|
|
|
|
const int q = strFilename.Find('?');
|
|
|
|
|
wxString strArgs;
|
|
|
|
|
if (q > 0)
|
|
|
|
|
{
|
|
|
|
|
strArgs = strFilename.Mid(q+1);
|
|
|
|
|
strFilename.Truncate(q);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxString strName;
|
|
|
|
|
wxSplitPath(strFilename, NULL, &strName, NULL);
|
|
|
|
|
strName.MakeLower();
|
|
|
|
|
|
|
|
|
|
if (strName == "index")
|
|
|
|
|
{
|
|
|
|
|
GenerateIndex(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "modules")
|
|
|
|
|
{
|
|
|
|
|
GenerateModules(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "users")
|
|
|
|
|
{
|
|
|
|
|
GenerateUsers(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "log")
|
|
|
|
|
{
|
|
|
|
|
strFilename = GetLogFileName();
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "activate")
|
|
|
|
|
{
|
|
|
|
|
const int nModule = atoi(strArgs);
|
|
|
|
|
|
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html);
|
|
|
|
|
TXmlItem& form = body.AddChild("form");
|
|
|
|
|
form.SetAttr("action", "activate"); form.SetAttr("method", "post");
|
|
|
|
|
|
|
|
|
|
TXmlItem& table = form.AddChild("center").AddChild("table");
|
|
|
|
|
table.SetAttr("width", "70%").SetAttr("border", "1");
|
|
|
|
|
table.AddChild("caption").AddChild("h2") << "Module Activation";
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr0 = table.AddChild("tr");
|
2003-12-05 12:11:57 +00:00
|
|
|
|
tr0.AddChild("td") << wxString::Format("Module %d", nModule);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
tr0.AddChild("td") << DescribeModule(nModule);
|
2003-12-05 12:11:57 +00:00
|
|
|
|
TXmlItem& module = tr0.AddChild("td").AddChild("input");
|
|
|
|
|
module.SetAttr("type", "hidden"); module.SetAttr("name", "module");
|
|
|
|
|
module.SetAttr("value", nModule);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
|
|
TXmlItem& tr1 = table.AddChild("tr");
|
|
|
|
|
tr1.AddChild("td") << "Activation date (dd-mm-yyyy)";
|
|
|
|
|
TXmlItem& date = tr1.AddChild("td").AddChild("input");
|
|
|
|
|
date.SetAttr("type", "string"); date.SetAttr("name", "date");
|
|
|
|
|
date.SetAttr("size", "10"); date.SetAttr("maxlength", "10");
|
|
|
|
|
date.SetAttr("value", Date2String(wxDateTime::Now()));
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr2 = table.AddChild("tr");
|
|
|
|
|
tr2.AddChild("td") << "Activation code";
|
|
|
|
|
|
|
|
|
|
TXmlItem& key = tr2.AddChild("td").AddChild("input");
|
|
|
|
|
key.SetAttr("type", "string"); key.SetAttr("name", "key");
|
|
|
|
|
key.SetAttr("size", "8"); key.SetAttr("maxlength", "8");
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr3 = table.AddChild("tr");
|
|
|
|
|
tr3.AddChild("td").AddChild("a").SetAttr("href", "/") << "Return to main page";
|
|
|
|
|
TXmlItem& submit = tr3.AddChild("td").AddChild("input");
|
|
|
|
|
submit.SetAttr("type", "submit");
|
|
|
|
|
submit.SetAttr("value", "Confirm Activation");
|
|
|
|
|
|
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "deactivate")
|
|
|
|
|
{
|
|
|
|
|
const int nModule = atoi(strArgs);
|
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html).AddChild("center");
|
|
|
|
|
body.AddChild("h1") << "WARNING!";
|
|
|
|
|
body.AddChild("br");
|
|
|
|
|
body.AddChild("h3") << "You are about to deactivate the following module:";
|
|
|
|
|
body.AddChild("br");
|
|
|
|
|
body.AddChild("h2") << DescribeModule(nModule);
|
|
|
|
|
body.AddChild("br");
|
|
|
|
|
TXmlItem& form = body.AddChild("form");
|
|
|
|
|
form.SetAttr("action", "deactivate"); form.SetAttr("method", "post");
|
|
|
|
|
TXmlItem& module = form.AddChild("input");
|
|
|
|
|
module.SetAttr("type", "hidden");
|
|
|
|
|
module.SetAttr("name", "module");
|
|
|
|
|
module.SetAttr("value", wxString::Format("%d", nModule));
|
|
|
|
|
|
|
|
|
|
TXmlItem& submit = form.AddChild("input");
|
|
|
|
|
submit.SetAttr("type", "submit");
|
|
|
|
|
submit.SetAttr("value", "Confirm Deactivation");
|
|
|
|
|
|
|
|
|
|
body.AddChild("br"); body.AddChild("br");
|
|
|
|
|
AddLinkButton(body, "Return to modules list", "Modules");
|
|
|
|
|
|
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "year")
|
|
|
|
|
{
|
2004-03-25 10:35:14 +00:00
|
|
|
|
// const int nModule = atoi(strArgs);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html);
|
|
|
|
|
TXmlItem& form = body.AddChild("form");
|
|
|
|
|
form.SetAttr("action", "year"); form.SetAttr("method", "post");
|
|
|
|
|
|
|
|
|
|
TXmlItem& table = form.AddChild("center").AddChild("table");
|
|
|
|
|
table.SetAttr("width", "70%").SetAttr("border", "1");
|
|
|
|
|
table.AddChild("caption").AddChild("h2") << "Year of Assistance";
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr0 = table.AddChild("tr");
|
|
|
|
|
tr0.AddChild("td") << "Assistance year to be activated";
|
|
|
|
|
|
|
|
|
|
TXmlItem& year = tr0.AddChild("td").AddChild("input");
|
|
|
|
|
year.SetAttr("type", "string"); year.SetAttr("name", "year");
|
|
|
|
|
year.SetAttr("size", "4"); year.SetAttr("maxlength", "4");
|
|
|
|
|
year.SetAttr("value", wxString::Format("%d", m_Dongle.YearAssist()+1));
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr1 = table.AddChild("tr");
|
|
|
|
|
tr1.AddChild("td") << "Activation date (dd-mm-yyyy)";
|
|
|
|
|
TXmlItem& date = tr1.AddChild("td").AddChild("input");
|
|
|
|
|
date.SetAttr("type", "string"); date.SetAttr("name", "date");
|
|
|
|
|
date.SetAttr("size", "10"); date.SetAttr("maxlength", "10");
|
|
|
|
|
date.SetAttr("value", Date2String(wxDateTime::Now()));
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr2 = table.AddChild("tr");
|
|
|
|
|
tr2.AddChild("td") << "Activation code";
|
|
|
|
|
|
|
|
|
|
TXmlItem& key = tr2.AddChild("td").AddChild("input");
|
|
|
|
|
key.SetAttr("type", "string"); key.SetAttr("name", "key");
|
|
|
|
|
key.SetAttr("size", "8"); key.SetAttr("maxlength", "8");
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr3 = table.AddChild("tr");
|
|
|
|
|
tr3.AddChild("td").AddChild("a").SetAttr("href", "/") << "Return to main page";
|
|
|
|
|
TXmlItem& submit = tr3.AddChild("td").AddChild("input");
|
|
|
|
|
submit.SetAttr("type", "submit");
|
|
|
|
|
submit.SetAttr("value", "Confirm Activation");
|
|
|
|
|
|
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "maxusers")
|
|
|
|
|
{
|
2004-03-25 10:35:14 +00:00
|
|
|
|
// const int nModule = atoi(strArgs);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
TXmlItem html;
|
|
|
|
|
TXmlItem& body = CreatePageBody(html);
|
|
|
|
|
TXmlItem& form = body.AddChild("form");
|
|
|
|
|
form.SetAttr("action", "maxusers"); form.SetAttr("method", "post");
|
|
|
|
|
|
|
|
|
|
TXmlItem& table = form.AddChild("center").AddChild("table");
|
|
|
|
|
table.SetAttr("width", "70%").SetAttr("border", "1");
|
|
|
|
|
table.AddChild("caption").AddChild("h2") << "Maximum Users";
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr0 = table.AddChild("tr");
|
|
|
|
|
tr0.AddChild("td") << "Number of users";
|
|
|
|
|
|
|
|
|
|
TXmlItem& year = tr0.AddChild("td").AddChild("input");
|
|
|
|
|
year.SetAttr("type", "string"); year.SetAttr("name", "users");
|
|
|
|
|
year.SetAttr("size", "4"); year.SetAttr("maxlength", "4");
|
|
|
|
|
year.SetAttr("value", wxString::Format("%d", m_Dongle.MaxUsers()));
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr1 = table.AddChild("tr");
|
|
|
|
|
tr1.AddChild("td") << "Activation date (dd-mm-yyyy)";
|
|
|
|
|
TXmlItem& date = tr1.AddChild("td").AddChild("input");
|
|
|
|
|
date.SetAttr("type", "string"); date.SetAttr("name", "date");
|
|
|
|
|
date.SetAttr("size", "10"); date.SetAttr("maxlength", "10");
|
|
|
|
|
date.SetAttr("value", Date2String(wxDateTime::Now()));
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr2 = table.AddChild("tr");
|
|
|
|
|
tr2.AddChild("td") << "Activation code";
|
|
|
|
|
|
|
|
|
|
TXmlItem& key = tr2.AddChild("td").AddChild("input");
|
|
|
|
|
key.SetAttr("type", "string"); key.SetAttr("name", "key");
|
|
|
|
|
key.SetAttr("size", "8"); key.SetAttr("maxlength", "8");
|
|
|
|
|
form.AddChild("br"); form.AddChild("br");
|
|
|
|
|
|
|
|
|
|
TXmlItem& tr3 = table.AddChild("tr");
|
|
|
|
|
tr3.AddChild("td").AddChild("a").SetAttr("href", "index") << "Return to main page";
|
|
|
|
|
TXmlItem& submit = tr3.AddChild("td").AddChild("input");
|
|
|
|
|
submit.SetAttr("type", "submit");
|
|
|
|
|
submit.SetAttr("value", "Confirm Activation");
|
|
|
|
|
|
|
|
|
|
strFilename = GetTempFilename();
|
|
|
|
|
html.Save(strFilename);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "kill")
|
|
|
|
|
{
|
|
|
|
|
m_Users.Kill(strArgs);
|
|
|
|
|
GenerateUsers(strFilename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::ProcessActivation(int nModule, bool act, wxSocketBase& outs)
|
|
|
|
|
{
|
|
|
|
|
if (nModule > 0)
|
|
|
|
|
{
|
|
|
|
|
if (act)
|
|
|
|
|
m_Dongle.Activate(nModule);
|
|
|
|
|
else
|
|
|
|
|
m_Dongle.Deactivate(nModule);
|
|
|
|
|
m_Dongle.Burn();
|
|
|
|
|
InitModules();
|
|
|
|
|
}
|
|
|
|
|
wxString strFileName = "Modules";
|
|
|
|
|
GenerateFile(strFileName);
|
|
|
|
|
SendFile(strFileName, outs);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-05 12:11:57 +00:00
|
|
|
|
bool TAuthorizationServer::KeyIsGood(const wxString& key, const wxString& gar) const
|
|
|
|
|
{
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
|
return key.IsSameAs(gar, false);
|
|
|
|
|
#else
|
|
|
|
|
return key.Length() == 8;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs)
|
|
|
|
|
{
|
|
|
|
|
const int stop = cmd.Find(" HTTP");
|
|
|
|
|
wxString strFileName = cmd.Mid(5, stop-5).Trim();
|
|
|
|
|
|
|
|
|
|
wxString strName, args;
|
|
|
|
|
wxSplitPath(strFileName, NULL, &strName, NULL);
|
|
|
|
|
strName.MakeLower();
|
|
|
|
|
|
|
|
|
|
const int pos = cmd.Find("\r\n\r\n");
|
|
|
|
|
if (pos > 0)
|
|
|
|
|
args = cmd.Mid(pos+4);
|
|
|
|
|
|
|
|
|
|
THashTable hashArgs(13);
|
|
|
|
|
ParseArguments(args, hashArgs);
|
|
|
|
|
|
|
|
|
|
if (strName == "activate")
|
|
|
|
|
{
|
|
|
|
|
const int nModule = hashArgs.GetInt("module");
|
|
|
|
|
const wxDateTime date = hashArgs.GetDate("date");
|
|
|
|
|
const wxString key = hashArgs.Get("key");
|
|
|
|
|
const wxString gar = Garble(nModule, date);
|
2003-12-05 12:11:57 +00:00
|
|
|
|
if (KeyIsGood(key, gar))
|
2002-10-24 10:47:49 +00:00
|
|
|
|
ProcessActivation(nModule, true, outs);
|
|
|
|
|
else
|
|
|
|
|
MessageBox("ERROR!", "You supplied the wrong activation code", outs);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "deactivate")
|
|
|
|
|
{
|
|
|
|
|
const int nModule = atoi(hashArgs.Get("module"));
|
|
|
|
|
ProcessActivation(nModule, false, outs);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "year")
|
|
|
|
|
{
|
|
|
|
|
const int year = hashArgs.GetInt("year");
|
|
|
|
|
const wxDateTime date = hashArgs.GetDate("date");
|
|
|
|
|
const wxString key = hashArgs.Get("key");
|
|
|
|
|
const wxString gar = Garble(year, date);
|
2003-12-05 12:11:57 +00:00
|
|
|
|
if (KeyIsGood(key, gar))
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
|
|
|
|
m_Dongle.set_year_assist(year);
|
|
|
|
|
m_Dongle.Burn();
|
|
|
|
|
wxString strFileName = "index";
|
|
|
|
|
GenerateFile(strFileName);
|
|
|
|
|
SendFile(strFileName, outs);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
MessageBox("ERROR!", "You supplied the wrong activation code", outs);
|
|
|
|
|
} else
|
|
|
|
|
if (strName == "maxusers")
|
|
|
|
|
{
|
|
|
|
|
const int users = atoi(hashArgs.Get("users"));
|
|
|
|
|
const wxDateTime date = hashArgs.GetDate("date");
|
|
|
|
|
const wxString key = hashArgs.Get("key");
|
|
|
|
|
const wxString gar = Garble(users, date);
|
2003-12-05 12:11:57 +00:00
|
|
|
|
if (KeyIsGood(key, gar))
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
|
|
|
|
m_Dongle.set_max_users(users);
|
|
|
|
|
m_Dongle.Burn();
|
|
|
|
|
wxString strFileName = "index";
|
|
|
|
|
GenerateFile(strFileName);
|
|
|
|
|
SendFile(strFileName, outs);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
MessageBox("ERROR!", "You supplied the wrong activation code", outs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-19 10:31:03 +00:00
|
|
|
|
unsigned int TAuthorizationServer::DecodePassword(const wxChar* strPassword, const wxChar* strApp)
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
|
|
|
|
const unsigned int BASE = 19;
|
|
|
|
|
unsigned int num = 0;
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
for (const wxChar* c = strPassword; *c; c++)
|
|
|
|
|
{
|
|
|
|
|
num *= BASE;
|
|
|
|
|
if (*c >= '0' && *c <= '9')
|
|
|
|
|
{
|
|
|
|
|
num += *c - '0';
|
2002-12-20 17:08:30 +00:00
|
|
|
|
}
|
2002-10-24 10:47:49 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (*c >= 'A' && *c <= 'Z')
|
|
|
|
|
{
|
|
|
|
|
num += *c - 'A' + 10;
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-12-20 17:08:30 +00:00
|
|
|
|
break; // Carattere non valido
|
2002-10-24 10:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
len++;
|
|
|
|
|
}
|
|
|
|
|
// Per essereva valido deve essere divisibile per 883
|
2003-12-19 10:31:03 +00:00
|
|
|
|
if (len >= 5 && (num%883) == 0)
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
2003-12-19 10:31:03 +00:00
|
|
|
|
if (m_strLastPassword != strPassword || m_strLastApp != strApp)
|
|
|
|
|
{
|
|
|
|
|
m_strLastPassword = strPassword;
|
|
|
|
|
m_strLastApp = strApp;
|
|
|
|
|
m_nPwdCount = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_nPwdCount++;
|
|
|
|
|
|
|
|
|
|
if (m_nPwdCount < 8)
|
|
|
|
|
{
|
|
|
|
|
// Creo la risposta: met<65> di num reso divisibile per 883
|
|
|
|
|
num /= 2;
|
|
|
|
|
while (num % 883 != 0)
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
num = 0;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
num = 0;
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock)
|
|
|
|
|
{
|
|
|
|
|
wxChar strUser[16];
|
|
|
|
|
wxChar strPassword[16];
|
|
|
|
|
wxChar strProgram[16];
|
2004-04-01 08:42:27 +00:00
|
|
|
|
int session;
|
2002-12-20 17:08:30 +00:00
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
cmd.Replace(",", " "); cmd.Replace(")", " ");
|
2004-04-01 08:42:27 +00:00
|
|
|
|
const int nStr = sscanf(cmd, "UserLogin(%s %s %s %d)", strUser, strPassword, strProgram, &session);
|
|
|
|
|
|
|
|
|
|
if (nStr < 4)
|
|
|
|
|
session = 0;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
|
unsigned int num = 0;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
if (m_Dongle.Connected())
|
|
|
|
|
{
|
2004-04-01 08:42:27 +00:00
|
|
|
|
// Preliminary GUEST login
|
|
|
|
|
// if (wxStricmp(strUser,"******")==0 && wxStricmp(strProgram, "ba0100")==0)
|
|
|
|
|
// {
|
|
|
|
|
// num = 1;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
{
|
2005-02-17 18:13:12 +00:00
|
|
|
|
if (m_Users.GetLicenses() >= m_Dongle.MaxUsers() && m_Users.Find(sock, NULL, session) == NULL)
|
2003-12-19 10:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
WriteLog("*** Maximum users exceeded");
|
2002-10-24 10:47:49 +00:00
|
|
|
|
num = 0;
|
2003-12-19 10:31:03 +00:00
|
|
|
|
}
|
2002-10-24 10:47:49 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2002-12-20 17:08:30 +00:00
|
|
|
|
if (strcmp(strPassword, "******") == 0) // Older 16 bit version
|
2002-10-24 10:47:49 +00:00
|
|
|
|
num = 1;
|
|
|
|
|
else
|
2003-12-19 10:31:03 +00:00
|
|
|
|
num = DecodePassword(strPassword, strProgram);
|
2002-12-20 17:08:30 +00:00
|
|
|
|
if (num > 0)
|
2004-04-01 08:42:27 +00:00
|
|
|
|
m_Users.AddConnection(sock, strUser, session);
|
2003-12-19 10:31:03 +00:00
|
|
|
|
else
|
|
|
|
|
WriteLog("*** Bad password");
|
2002-10-24 10:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-19 10:31:03 +00:00
|
|
|
|
else
|
|
|
|
|
WriteLog("*** Dongle not responding");
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
ReturnInt(sock, num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAuthorizationServer::ProcessUserLogout(wxString cmd, wxSocketBase& sock)
|
|
|
|
|
{
|
2004-04-01 08:42:27 +00:00
|
|
|
|
wxChar strUser[16];
|
2005-05-16 23:44:23 +00:00
|
|
|
|
wxChar strProgram[16];
|
2004-04-01 08:42:27 +00:00
|
|
|
|
int session;
|
|
|
|
|
|
|
|
|
|
cmd.Replace(",", " "); cmd.Replace(")", " ");
|
2005-05-16 23:44:23 +00:00
|
|
|
|
const int nStr = sscanf(cmd, "UserLogout(%s %d %s)", strUser, &session, strProgram);
|
2004-04-01 08:42:27 +00:00
|
|
|
|
|
|
|
|
|
if (nStr < 2)
|
|
|
|
|
session = 0;
|
|
|
|
|
|
|
|
|
|
m_Users.RemoveConnection(sock, strUser, session);
|
2005-05-16 23:44:23 +00:00
|
|
|
|
if (strcmp(strProgram, "ba0100") == 0)
|
|
|
|
|
m_Users.KillSession(sock, session);
|
2004-04-01 08:42:27 +00:00
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::ReturnInt(wxSocketBase& outs, unsigned int i)
|
|
|
|
|
{
|
|
|
|
|
const unsigned int buf[2] = { sizeof(i), i };
|
|
|
|
|
outs.Write(buf, sizeof(buf));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::ReturnBool(wxSocketBase& outs, bool b)
|
|
|
|
|
{
|
|
|
|
|
ReturnInt(outs, b ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAuthorizationServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
|
|
|
|
|
{
|
|
|
|
|
if (cmd.StartsWith("GET "))
|
|
|
|
|
{
|
|
|
|
|
const int stop = cmd.Find(" HTTP");
|
|
|
|
|
wxString str;
|
|
|
|
|
if (stop > 4)
|
|
|
|
|
str = cmd.Mid(4, stop-4).Trim();
|
|
|
|
|
else
|
|
|
|
|
str = cmd.Mid(4).Trim();
|
|
|
|
|
if (str == "/")
|
|
|
|
|
str += "index.htm";
|
|
|
|
|
wxString strFilename = GetDocumentRoot() + str;
|
|
|
|
|
|
|
|
|
|
if (IsMagicName(strFilename))
|
|
|
|
|
GenerateFile(strFilename);
|
|
|
|
|
|
|
|
|
|
SendFile(strFilename, outs);
|
|
|
|
|
} else
|
|
|
|
|
if (cmd.StartsWith("POST "))
|
|
|
|
|
{
|
|
|
|
|
ProcessFormCommand(cmd, outs);
|
|
|
|
|
} else
|
|
|
|
|
if (cmd.StartsWith("UserLogin"))
|
|
|
|
|
{
|
|
|
|
|
ProcessUserLogin(cmd, outs);
|
|
|
|
|
} else
|
|
|
|
|
if (cmd.StartsWith("UserLogout"))
|
|
|
|
|
{
|
|
|
|
|
bool ok = ProcessUserLogout(cmd, outs);
|
|
|
|
|
ReturnBool(outs, ok);
|
|
|
|
|
} else
|
|
|
|
|
if (cmd.StartsWith("DongleNumber"))
|
|
|
|
|
{
|
|
|
|
|
ReturnInt(outs, m_Dongle.Number());
|
|
|
|
|
} else
|
|
|
|
|
if (cmd.StartsWith("DongleYear"))
|
|
|
|
|
{
|
|
|
|
|
ReturnInt(outs, m_Dongle.YearAssist());
|
|
|
|
|
} else
|
|
|
|
|
if (cmd.StartsWith("DongleModules"))
|
|
|
|
|
{
|
|
|
|
|
outs.Write(m_Modules, sizeof(m_Modules));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
|
#define ATOMIC_SEMAPHORE "DONGLE_SERVER_ATOM"
|
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
|
bool TAuthorizationServer::Initialization()
|
|
|
|
|
{
|
2002-12-20 17:08:30 +00:00
|
|
|
|
#ifdef WIN32
|
|
|
|
|
// Add global atom if not already present
|
|
|
|
|
if (::GlobalFindAtom(ATOMIC_SEMAPHORE) == NULL)
|
|
|
|
|
::GlobalAddAtom(ATOMIC_SEMAPHORE); // Same as old Frontend.exe
|
|
|
|
|
#endif
|
2005-10-28 12:13:28 +00:00
|
|
|
|
int delay = GetConfigInt("Delay", 10);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i > 0)
|
|
|
|
|
wxSleep(delay);
|
|
|
|
|
if (m_Dongle.Login())
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-10-24 10:47:49 +00:00
|
|
|
|
InitModules();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAuthorizationServer::Deinitialization()
|
|
|
|
|
{
|
|
|
|
|
m_Dongle.Logout();
|
2002-12-20 17:08:30 +00:00
|
|
|
|
#ifdef WIN32
|
|
|
|
|
// Definitely kill global atom
|
|
|
|
|
for (ATOM a = ::GlobalFindAtom(ATOMIC_SEMAPHORE);
|
|
|
|
|
a != NULL;
|
|
|
|
|
a = ::GlobalDeleteAtom(a));
|
|
|
|
|
#endif
|
2002-10-24 10:47:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Istanziare l'applicazione principale
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_APP(TAuthorizationServer)
|