Patch level : 10.0
Files correlati : authoriz.exe Ricompilazione Demo : [ ] Commento : Corretta gestione abilitazione moduli, anni ed utenti con codici generati da chiave o da sito git-svn-id: svn://10.65.10.50/branches/R_10_00@21725 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
6dab34978e
commit
26428c46a9
@ -158,12 +158,18 @@ protected:
|
||||
|
||||
void AddNumber(TXmlItem& tr, int n) const;
|
||||
wxString DescribeModule(int m) const;
|
||||
wxString ModuleCode(int m) const;
|
||||
bool KeyIsGood(const wxString& key, const wxString& gar) const;
|
||||
|
||||
void InitModules();
|
||||
wxString GetModulesFilename() const;
|
||||
wxString Garble(unsigned short n, const wxDateTime& date) const;
|
||||
wxString GarbleMD5(unsigned short n, const wxDateTime& date) const;
|
||||
|
||||
wxString GarbleMD5(const char* str, const wxDateTime& date) const;
|
||||
wxString GarbleMD5(int n, const wxDateTime& date) const;
|
||||
|
||||
void GarbleModule(unsigned short n, const wxDateTime& date, wxString& g1, wxString& g2) const;
|
||||
void GarbleYear(int n, const wxDateTime& date, wxString& g1, wxString& g2) const;
|
||||
void GarbleUsers(int n, const wxDateTime& date, wxString& g1, wxString& g2) const;
|
||||
|
||||
public:
|
||||
bool IsMagicName(wxString& strFilename) const;
|
||||
@ -206,33 +212,64 @@ void TAuthorizationServer::InitModules()
|
||||
}
|
||||
}
|
||||
|
||||
wxString TAuthorizationServer::Garble(unsigned short n, const wxDateTime& date) const
|
||||
wxString TAuthorizationServer::GarbleMD5(const char* str, const wxDateTime& date) const
|
||||
{
|
||||
const long nANSIdate = date.GetYear()*10000 + (date.GetMonth()+1)*100 + date.GetDay();
|
||||
wxString chiaro; chiaro.Printf("%8ld%d%s", nANSIdate, m_Dongle.Number(), str);
|
||||
|
||||
unsigned char* buffer = (unsigned char*)chiaro.c_str();
|
||||
const wxString cifrato = wxMD5Checksum::GetMD5(buffer, chiaro.Len());
|
||||
return cifrato.Right(8);
|
||||
}
|
||||
|
||||
wxString TAuthorizationServer::GarbleMD5(int n, const wxDateTime& date) const
|
||||
{
|
||||
char str[16]; wxSprintf(str, "%d", n);
|
||||
return GarbleMD5(str, date);
|
||||
}
|
||||
|
||||
void TAuthorizationServer::GarbleYear(int y, const wxDateTime& date,
|
||||
wxString& g1, wxString& g2) const
|
||||
{
|
||||
const long val = date2julian(date);
|
||||
|
||||
unsigned short data[4];
|
||||
data[0] = m_Dongle.Number();
|
||||
data[1] = n;
|
||||
data[2] = (unsigned short)(val >> 16);
|
||||
data[1] = (unsigned short)(val >> 16);
|
||||
data[2] = y;
|
||||
data[3] = (unsigned short)(val & 0xFFFF);
|
||||
m_Dongle.garble(data);
|
||||
return wxString::Format("%04X%04X", data[0], data[1]);
|
||||
g1.Printf("%04X%04X", data[0], data[1]);
|
||||
g2 = GarbleMD5(y, date);
|
||||
}
|
||||
|
||||
wxString TAuthorizationServer::GarbleMD5(unsigned short n, const wxDateTime& date) const
|
||||
void TAuthorizationServer::GarbleUsers(int u, const wxDateTime& date,
|
||||
wxString& g1, wxString& g2) const
|
||||
{
|
||||
const long nANSIdate = date.GetYear()*10000 + (date.GetMonth()+1)*100 + date.GetDay();
|
||||
const long val = date2julian(date);
|
||||
unsigned short data[4];
|
||||
data[0] = u;
|
||||
data[1] = (unsigned short)(val >> 16);
|
||||
data[2] = m_Dongle.Number();
|
||||
data[3] = (unsigned short)(val & 0xFFFF);
|
||||
m_Dongle.garble(data);
|
||||
g1.Printf("%04X%04X", data[0], data[1]);
|
||||
g2 = GarbleMD5(u, date);
|
||||
}
|
||||
|
||||
wxString strModule;
|
||||
wxTextFile txt(GetModulesFilename());
|
||||
if (txt.Open())
|
||||
strModule = txt.GetLine(n).Left(2).Upper();
|
||||
|
||||
wxString chiaro; chiaro.Printf("%8ld%d%s", nANSIdate, m_Dongle.Number(), strModule);
|
||||
|
||||
unsigned char* buffer = (unsigned char*)chiaro.c_str();
|
||||
const wxString cifrato = wxMD5Checksum::GetMD5(buffer, chiaro.Len());
|
||||
return cifrato.Right(8);
|
||||
void TAuthorizationServer::GarbleModule(unsigned short m, const wxDateTime& date,
|
||||
wxString& g1, wxString& g2) const
|
||||
{
|
||||
const long val = date2julian(date);
|
||||
|
||||
unsigned short data[4];
|
||||
data[0] = m_Dongle.Number();
|
||||
data[1] = (unsigned short)(val >> 16);
|
||||
data[2] = m;
|
||||
data[3] = (unsigned short)(val & 0xFFFF);
|
||||
m_Dongle.garble(data);
|
||||
g1.Printf("%04X%04X", data[0], data[1]);
|
||||
g2 = GarbleMD5(ModuleCode(m), date);
|
||||
}
|
||||
|
||||
// Implementare almeno queste due funzioni pure virtuali
|
||||
@ -272,16 +309,20 @@ wxString TAuthorizationServer::GetModulesFilename() const
|
||||
|
||||
wxString TAuthorizationServer::DescribeModule(int m) const
|
||||
{
|
||||
const wxString strAut = GetModulesFilename();
|
||||
wxFileInputStream aut(strAut);
|
||||
wxString line;
|
||||
for (int nModule = 0; !aut.Eof(); nModule++)
|
||||
{
|
||||
aut >> line;
|
||||
if (nModule == m)
|
||||
return line.Mid(3).Trim();
|
||||
}
|
||||
return line; // Should never happen!
|
||||
wxString strModule;
|
||||
wxTextFile txt(GetModulesFilename());
|
||||
if (txt.Open())
|
||||
strModule = txt.GetLine(m).Mid(3);
|
||||
return strModule;
|
||||
}
|
||||
|
||||
wxString TAuthorizationServer::ModuleCode(int m) const
|
||||
{
|
||||
wxString strModule;
|
||||
wxTextFile txt(GetModulesFilename());
|
||||
if (txt.Open())
|
||||
strModule = txt.GetLine(m).Left(2).Upper();
|
||||
return strModule;
|
||||
}
|
||||
|
||||
void TAuthorizationServer::AddNumber(TXmlItem& tr, int n) const
|
||||
@ -407,7 +448,7 @@ void TAuthorizationServer::GenerateModules(wxString& strFilename)
|
||||
if (line.IsEmpty())
|
||||
break;
|
||||
|
||||
const wxString strCode = line.Left(2);
|
||||
const wxString strCode = line.Left(2).Lower();
|
||||
const wxString strDesc = line.Mid(3);
|
||||
if (nModule > 0 && strCode != "xx" && !strDesc.IsEmpty())
|
||||
{
|
||||
@ -513,7 +554,8 @@ void TAuthorizationServer::GenerateFile(wxString& strFilename)
|
||||
TXmlItem html;
|
||||
TXmlItem& body = CreatePageBody(html);
|
||||
TXmlItem& form = body.AddChild("form");
|
||||
form.SetAttr("action", "activate"); form.SetAttr("method", "post");
|
||||
form.SetAttr("action", "activate");
|
||||
form.SetAttr("method", "post");
|
||||
|
||||
TXmlItem& table = form.AddChild("center").AddChild("table");
|
||||
table.SetAttr("width", "70%").SetAttr("border", "1");
|
||||
@ -545,6 +587,7 @@ void TAuthorizationServer::GenerateFile(wxString& strFilename)
|
||||
TXmlItem& submit = tr3.AddChild("td").AddChild("input");
|
||||
submit.SetAttr("type", "submit");
|
||||
submit.SetAttr("value", "Confirm Activation");
|
||||
submit.SetAttr("title", wxString::Format("Activate module %d", nModule));
|
||||
|
||||
strFilename = GetTempFilename();
|
||||
html.Save(strFilename);
|
||||
@ -621,7 +664,6 @@ void TAuthorizationServer::GenerateFile(wxString& strFilename)
|
||||
} else
|
||||
if (strName == "maxusers")
|
||||
{
|
||||
// const int nModule = atoi(strArgs);
|
||||
TXmlItem html;
|
||||
TXmlItem& body = CreatePageBody(html);
|
||||
TXmlItem& form = body.AddChild("form");
|
||||
@ -712,8 +754,8 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs)
|
||||
const int nModule = hashArgs.GetInt("module");
|
||||
const wxDateTime date = hashArgs.GetDate("date");
|
||||
const wxString key = hashArgs.Get("key");
|
||||
const wxString gar1 = Garble(nModule, date);
|
||||
const wxString gar2 = GarbleMD5(nModule, date);
|
||||
wxString gar1, gar2;
|
||||
GarbleModule(nModule, date, gar1, gar2);
|
||||
if (KeyIsGood(key, gar1) || KeyIsGood(key, gar2))
|
||||
ProcessModuleActivation(nModule, true, outs);
|
||||
else
|
||||
@ -729,8 +771,8 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs)
|
||||
const int year = hashArgs.GetInt("year");
|
||||
const wxDateTime date = hashArgs.GetDate("date");
|
||||
const wxString key = hashArgs.Get("key");
|
||||
const wxString gar1 = Garble(year, date);
|
||||
const wxString gar2 = GarbleMD5(year, date);
|
||||
wxString gar1, gar2;
|
||||
GarbleYear(year, date, gar1, gar2);
|
||||
if (KeyIsGood(key, gar1) || KeyIsGood(key, gar2))
|
||||
{
|
||||
m_Dongle.set_year_assist(year);
|
||||
@ -747,8 +789,8 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs)
|
||||
const int users = atoi(hashArgs.Get("users"));
|
||||
const wxDateTime date = hashArgs.GetDate("date");
|
||||
const wxString key = hashArgs.Get("key");
|
||||
const wxString gar1 = Garble(users, date);
|
||||
const wxString gar2 = GarbleMD5(users, date);
|
||||
wxString gar1, gar2;
|
||||
GarbleUsers(users, date, gar1, gar2);
|
||||
if (KeyIsGood(key, gar1) || KeyIsGood(key, gar2))
|
||||
{
|
||||
m_Dongle.set_max_users(users);
|
||||
|
Loading…
x
Reference in New Issue
Block a user