Patch level :

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :


git-svn-id: svn://10.65.10.50/trunk@15613 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
luca 2007-09-13 10:24:51 +00:00
parent 5674651824
commit 614cf9d5bf
3 changed files with 369 additions and 300 deletions

View File

@ -11,7 +11,6 @@
#include <wx/mimetype.h>
#include <wx/progdlg.h>
#include <wx/radiobox.h>
#include <wx/socket.h>
#include <wx/txtstrm.h>
#include <wx/wfstream.h>
#include <wx/wizard.h>
@ -21,11 +20,7 @@
#include <shlobj.h>
#endif
extern "C"
{
#include "../xvaga/hlapi_c.h"
#include "../xvaga/skeylink.h"
}
#include "setupkey.h"
#define HGAP 4
#define VGAP 2
@ -33,18 +28,6 @@ extern "C"
///////////////////////////////////////////////////////////
// Utilities
///////////////////////////////////////////////////////////
bool ErrorBox(const wxString str)
{
wxMessageBox(str, APPNAME, wxOK | wxICON_ERROR);
return false;
}
bool WarningBox(const wxString str)
{
wxMessageBox(str, APPNAME, wxOK | wxICON_EXCLAMATION);
return false;
}
wxString GetDefaultDestination()
{
wxString strDest;
@ -420,12 +403,10 @@ CampoWizardPage1::CampoWizardPage1(wxWizard* parent) : CampoWizardPage(parent)
/**********************************************************************************************************/
/* 2 Pagina con la scelta di Aggiornamento / Tipo Installazione */
/**********************************************************************************************************/
// 2 Pagina con Accetta / Rifiuta la licenza
//*********************************************************************************************************/
class CampoWizardPage2 : public CampoWizardPage
{
wxRadioBox* m_pRadioBox;
protected:
virtual bool ForwardValidate();
@ -434,6 +415,44 @@ public:
};
bool CampoWizardPage2::ForwardValidate()
{
if (GetSelection(201) == 1)
return ErrorBox("Impossibile proseguire se non si accetta la licenza sul software!!");
return true;
}
CampoWizardPage2::CampoWizardPage2(wxWizard* parent) : CampoWizardPage(parent)
{
SetHTMLPage("licenza.htm");
//radiobutton Accetta / Rifiuta
wxArrayString asAccRef;
asAccRef.Add("Accetta");
asAccRef.Add("Rifiuta");
wxRadioBox* radio_box = new wxRadioBox(this, 201, "Selezionare 'Accetta' per proseguire con l'installazione, 'Rifiuta' per terminare l'installazione", wxDefaultPosition,
wxDefaultSize, asAccRef, 0, wxRA_SPECIFY_COLS);
radio_box->SetSelection(1);
GetSizer()->Add(radio_box);
}
/**********************************************************************************************************/
/* 3 Pagina con la scelta di Aggiornamento / Tipo Installazione */
/**********************************************************************************************************/
class CampoWizardPage3 : public CampoWizardPage
{
wxRadioBox* m_pRadioBox;
protected:
virtual bool ForwardValidate();
public:
CampoWizardPage3(wxWizard* parent);
};
bool CampoWizardPage3::ForwardValidate()
{
const int iLastRow = m_pRadioBox->GetRowCount() - 1;
const int iSelectedRow = m_pRadioBox->GetSelection();
@ -491,7 +510,7 @@ bool CampoWizardPage2::ForwardValidate()
return true;
}
CampoWizardPage2::CampoWizardPage2(wxWizard* parent) : CampoWizardPage(parent)
CampoWizardPage3::CampoWizardPage3(wxWizard* parent) : CampoWizardPage(parent)
{
//deve cercare campo.stp
CampoIniFile campo_stp("C:\\campo.stp", "");
@ -539,7 +558,7 @@ CampoWizardPage2::CampoWizardPage2(wxWizard* parent) : CampoWizardPage(parent)
strBody += wxT("<p>E' possibile <b>INSTALLARE <i>Campo</i></b> in un nuovo direttorio.</p>");
asCampi.Add("Nuova installazione"); //voce di nuova installazione!
m_pRadioBox = new wxRadioBox(this, 201, "Installazione del software", wxDefaultPosition,
m_pRadioBox = new wxRadioBox(this, 301, "Installazione del software", wxDefaultPosition,
wxDefaultSize, asCampi, 0, wxRA_SPECIFY_ROWS);
}
//..senno' propone di aggiornare
@ -554,7 +573,7 @@ CampoWizardPage2::CampoWizardPage2(wxWizard* parent) : CampoWizardPage(parent)
//radiobutton con le scelte aggiornamento
asCampi.Add("Nuova installazione");
m_pRadioBox = new wxRadioBox(this, 201, "Selezionare l'installazione da aggiornare (consigliato) o Nuova installazione", wxDefaultPosition,
m_pRadioBox = new wxRadioBox(this, 301, "Selezionare l'installazione da aggiornare (consigliato) o Nuova installazione", wxDefaultPosition,
wxDefaultSize, asCampi, 0, wxRA_SPECIFY_ROWS);
if (prechecked > 0)
m_pRadioBox->SetSelection(prechecked);
@ -565,69 +584,26 @@ CampoWizardPage2::CampoWizardPage2(wxWizard* parent) : CampoWizardPage(parent)
SetHTMLText(strTitle, strBody);
GetSizer()->Add(m_pRadioBox);
}
/**********************************************************************************************************/
// 3 Pagina con Accetta / Rifiuta la licenza
//*********************************************************************************************************/
class CampoWizardPage3 : public CampoWizardPage
{
protected:
virtual bool ForwardValidate();
public:
CampoWizardPage3(wxWizard* parent);
};
bool CampoWizardPage3::ForwardValidate()
{
if (GetSelection(301) == 1)
return ErrorBox("Impossibile proseguire se non si accetta la licenza sul software!!");
return true;
}
CampoWizardPage3::CampoWizardPage3(wxWizard* parent) : CampoWizardPage(parent)
{
SetHTMLPage("licenza.htm");
//radiobutton Accetta / Rifiuta
wxArrayString asAccRef;
asAccRef.Add("Accetta");
asAccRef.Add("Rifiuta");
wxRadioBox* radio_box = new wxRadioBox(this, 301, "Selezionare 'Accetta' per proseguire con l'installazione, 'Rifiuta' per terminare l'installazione", wxDefaultPosition,
wxDefaultSize, asAccRef, 0, wxRA_SPECIFY_COLS);
radio_box->SetSelection(1);
GetSizer()->Add(radio_box);
}
/**********************************************************************************************************/
/* 4 Pagina con la gestione della chiave di protezione */
/**********************************************************************************************************/
class CampoWizardPage4 : public CampoWizardPage
{
int _dongle_type;
protected:
DECLARE_EVENT_TABLE();
void OnHLPick(wxCommandEvent& e);
void OnEUPick(wxCommandEvent& e);
virtual bool ForwardValidate();
virtual bool TransferDataToWindow();
int DongleTest(const wxString& strSrvName = wxEmptyString);
int ThisYear();
int DongleTest();
wxString DecodeString(const wxString& data);
int VersionYear();
void BuildKey(char* key);
bool HardlockGarble(unsigned short* data);
unsigned short HardlockLogin(int& year);
void EncodeEutronPassword(char* str);
unsigned short EutronLogin(int& year);
unsigned short InquireSocketNumber(wxSocketClient& sc, const wxString& strCommand);
unsigned short InquireServer(const wxString& strSrvName, int& year);
unsigned short ServerLogin(int& year, const wxString& strSrvName);
public:
CampoWizardPage4(wxWizard* parent);
};
@ -649,175 +625,73 @@ void CampoWizardPage4::OnEUPick(wxCommandEvent& e)
wxString path("../chiavi/eutron/sdi.exe");
wxExecute(path, wxEXEC_SYNC);
}
///////////////////////////////
// Gestione chiave Hardlock //
///////////////////////////////
bool CampoWizardPage4::HardlockGarble(unsigned short* data)
bool CampoWizardPage4::ForwardValidate()
{
HL_CODE(data, 1);
/* int serno = 0xFFFF;
if (Get(403) != "")
{
serno = ServerLogin(0, Get(403));
}
if (serno == 0xFFFF)
return ErrorBox("Impossibile trovare la chiave in rete!!");*/
return true;
}
unsigned short CampoWizardPage4::HardlockLogin(int& year)
bool CampoWizardPage4::TransferDataToWindow()
{
unsigned short serno = 0xFFFF;
unsigned char REFKEY[16] = "CAMPOKEY";
unsigned char VERKEY[16] = "ìpÙˆ¬cê<";
if (HL_LOGIN(26952, LOCAL_DEVICE, REFKEY, VERKEY) == STATUS_OK)
{
unsigned short eprom[64]; memset(eprom, 0, sizeof(eprom));
HL_READBL((unsigned char*)eprom);
unsigned short data[4];
memcpy(data, eprom, sizeof(data));
HardlockGarble(data);
if (data[0] == 0xFAE8)
serno = data[1];
else
serno = 0;
memcpy(data, &eprom[60], sizeof(data));
if (HardlockGarble(data))
year = (int)data[0];
}
return serno;
}
FindWindowById(401)->Disable();
FindWindowById(402)->Disable();
FindWindowById(403)->Disable();
///////////////////////////////
// Gestione chiave Eutron //
///////////////////////////////
void CampoWizardPage4::EncodeEutronPassword(char* str)
{
const char* const key = "QSECOFR-";
char tmp[16];
int i;
for (i = 0; str[i]; i++)
tmp[i] = str[i] + (i < 8 ? key[i] : str[i - 8]);
tmp[i] = '\0';
strcpy(str, tmp);
}
//controlla preventivamente se la chiave c'e' ed eventualmente quale e' (hardlock,eutron,server di chiavi)
const int nDongleType = DongleTest();
GetWizard().SetDongleType(nDongleType);
unsigned short CampoWizardPage4::EutronLogin(int& year)
{
unsigned short serno = 0xFFFF;
const char* const login[2] = { "AGA.CAMPO", "25EBAI" };
for (int i = 0; i < 2; i++)
wxString strTitle = wxT("Controllo della chiave hardware di protezione");
wxString strBody = wxT("<p>La versione commerciale del software richiede l'installazione e la presenza della chiave hardware di protezione</p>");
switch (nDongleType)
{
KEY_NET eutron_key;
memset(&eutron_key, 0, sizeof(KEY_NET));
eutron_key.net_command = NET_KEY_OPEN;
eutron_key.command = LOCATING_MODE;
const char* const chiaro = login[i];
char cifrato[16];
strcpy(cifrato, chiaro);
EncodeEutronPassword(cifrato);
memset(eutron_key.label, 0, LABEL_LENGTH);
strcpy((char*)eutron_key.label, chiaro);
memset(eutron_key.password, 0, PASSWORD_LENGTH);
strcpy((char*)eutron_key.password, cifrato);
case 1:
strBody += wxT("<p>E' stata rilevata una chiave tipo <b>Hardlock</b>:</p>");
strBody += wxT("<p align=center><img src=\"../campo/servers/hardlock.gif\" /></p>");
strBody += wxT("<p>Si puo' procedere con l'installazione /aggiornamento del software <b><i>Campo</i></b>. Premere il pulsante \"Next\".</p>");
break;
case 2:
strBody += wxT("<p>E' stata rilevata una chiave tipo <b>Eutron</b>:</p>");
strBody += wxT("<p align=center><img src=\"../campo/servers/eutron.gif\" /></p>");
strBody += wxT("<p>Si puo' procedere con l'installazione /aggiornamento del software <b><i>Campo</i></b>. Premere il pulsante \"Next\".</p>");
break;
case 3:
strBody += wxT("<p>E' stato rilevata una chiave remota condivisa in rete con il servizio di gestione autorizzazioni:</p>");
strBody += wxT("<p align=center><img src=\"../campo/servers/autho.gif\" /></p>");
strBody += wxT("<p>Si puo' procedere con l'installazione /aggiornamento del software <b><i>Campo</i></b>. Premere il pulsante \"Next\".</p>");
Set(403, GetWizard().GetSrvAuth());
break;
smartlink(&eutron_key);
if (eutron_key.status == ST_OK)
{
eutron_key.net_command = NET_KEY_ACCESS;
eutron_key.command = BLOCK_READING_MODE;
short* pointer = (short*)(&eutron_key.data[0]);
short* number = (short*)(&eutron_key.data[2]);
*pointer = 0; // Posizione in cui leggere
*number = 8; // Words da leggere
smartlink(&eutron_key);
if (eutron_key.status == ST_OK)
{
serno = (unsigned short)atol((const char*)eutron_key.data+4);
if (i == 0)
{
const unsigned short y = *(unsigned short*)(eutron_key.data+12);
if (y > 2000 && y < 3000)
year = y;
}
else
year = ThisYear();
break;
}
}
}
return serno;
}
//////////////////////////////////
// Gestione Server di chiavi //
//////////////////////////////////
unsigned short CampoWizardPage4::InquireSocketNumber(wxSocketClient& sc, const wxString& strCommand)
{
sc.Write(strCommand, (wxUint32)strCommand.Len());
long number[2] = { 0L, 0L };
sc.Read(number, sizeof(number));
return (unsigned short)number[1];
}
unsigned short CampoWizardPage4::InquireServer(const wxString& strSrvName, int& year)
{
wxIPV4address ip;
if (!ip.Hostname(strSrvName) || !ip.Service("1883")) //indirizzo NON valido o porta scazzata!
{
ErrorBox("Indirizzo IP errato!");
return 0xFFFF;
}
wxSocketClient sc;
if (!sc.Connect(ip)) //il computer remoto risponde ma il server no (non c'e' o e' spento)
{
ErrorBox("Il server specificato non e' raggiungibile!");
return 0xFFFF;
default:
strBody += wxT("<p><b>Non e' stata rilevata alcuna chiave hardware installata sul computer!</b></p>");
strBody += wxT("<p>Per procedere all'installazione della chiave hardware, <u>collegarla al computer e premere il bottone corrispondente</u> alla tipologia della chiave stessa per installarne i driver.</p>");
strBody += wxT("<p>Se si utilizza una chiave remota collegata ad un altro computer e condivisa in rete attraverso il servizio gestione di autorizzazioni ");
strBody += wxT("<u>indicare il nome del computer (o l'indirizzo IP) cui e' collegata la chiave e su cui e' <b>installato e funzionante</b> il gestore di autorizzazioni</u>. ");
FindWindowById(401)->Enable();
FindWindowById(402)->Enable();
FindWindowById(403)->Enable();
break;
}
unsigned short serno = InquireSocketNumber(sc, "DongleNumber()");
year = InquireSocketNumber(sc, "DongleYear()");
SetHTMLText(strTitle, strBody);
return serno;
return true;
}
unsigned short CampoWizardPage4::ServerLogin(int& year, const wxString& strSrvName)
{
unsigned short serno = 0xFFFF;
//se non specificato un nome/indirizzo di server, lo cerca tra i miei "cpu fratelli" in rete
if (strSrvName.IsEmpty())
{
}
else //se invece e' specificato un server vede se il server di chiavi c'e' e funziona davvero
{
}
serno = InquireServer("localhost", year);
return serno;
}
/////////////////////////////////////////////////////////
// Metodi generici per le chiavi ed i relativi codici //
/////////////////////////////////////////////////////////
void CampoWizardPage4::BuildKey(char* key)
{
for (int i = 0; i < 8; i++)
key[i] = 'A'+ rand()%26;
}
int CampoWizardPage4::ThisYear()
{
int anno = 2006;
time_t lt;
if (time(&lt) == 0)
{
struct tm* timeloc = localtime(&lt) ;
if (timeloc != NULL)
anno = timeloc->tm_year + 1900;
}
return anno;
}
wxString CampoWizardPage4::DecodeString(const wxString& data)
{
char key[8] = "";
@ -839,9 +713,10 @@ int CampoWizardPage4::VersionYear()
return atoi(ver);
}
int CampoWizardPage4::DongleTest(const wxString& strSrvName)
int CampoWizardPage4::DongleTest()
{
_dongle_type = 0;
wxString strSrvName = GetWizard().GetSrvAuth(); //nome del server di autorizzazioni (se c'e')
int dongle_type = 0;
int yearKey = 0;
unsigned int serno = 0xFFFF;
@ -850,7 +725,7 @@ int CampoWizardPage4::DongleTest(const wxString& strSrvName)
{
serno = ServerLogin(yearKey, strSrvName);
if (serno != 0xFFFF)
_dongle_type = 3; //chiave remota
dongle_type = 3; //chiave remota
}
if (serno == 0xFFFF)
@ -860,25 +735,28 @@ int CampoWizardPage4::DongleTest(const wxString& strSrvName)
{
serno = EutronLogin(yearKey);
if (serno != 0xFFFF)
_dongle_type = 2; //chiave eutron
dongle_type = 2; //chiave eutron
else
{
if (strSrvName.IsEmpty())
{
serno = ServerLogin(yearKey, strSrvName);
if (serno != 0xFFFF)
_dongle_type = 3; //chiave remota
{
dongle_type = 3; //chiave remota
GetWizard().SetSrvAuth(strSrvName);
}
}
}
}
else
_dongle_type = 1; //chiave hardlock
dongle_type = 1; //chiave hardlock
}
if (serno == 0) // Chiave di sviluppo
return _dongle_type;
return dongle_type;
if (serno == 0xFFFF) // Chiave inesistente o invisibile = Prima installazione o demo
return _dongle_type;
return dongle_type;
const int verYear = VersionYear();
if (yearKey < verYear) // Chiave già programmata con assistenza pagata
@ -925,85 +803,51 @@ int CampoWizardPage4::DongleTest(const wxString& strSrvName)
ErrorBox("Impossibile verificare il contratto di manutenzione");
}
}
return _dongle_type;
return dongle_type;
}
CampoWizardPage4::CampoWizardPage4(wxWizard* parent) : CampoWizardPage(parent)
{
_dongle_type = DongleTest(); //controlla se la chiave c'e' ed eventualmente quale e'
//procedura per la costruzione dei bottoni e delle immagini per l'installazione dei driver di chiave
//"griglia" contenitrice degli oggetti
wxString strTitle = wxT("Controllo della chiave hardware di protezione");
wxString strBody = wxT("<p>La versione commerciale del software richiede l'installazione e la presenza della chiave hardware di protezione</p>");
switch (_dongle_type)
{
case 1:
strBody += wxT("<p>E' stata rilevata una chiave tipo <b>Hardlock</b>:</p>");
strBody += wxT("<p align=center><img src=\"hardlock.gif\" /></p>");
strBody += wxT("<p>Si puo' procedere con l'installazione /aggiornamento del software <b><i>Campo</i></b>. Premere il pulsante \"Next\".</p>");
break;
case 2:
strBody += wxT("<p>E' stata rilevata una chiave tipo <b>Eutron</b>:</p>");
strBody += wxT("<p align=center><img src=\"eutron.gif\" /></p>");
strBody += wxT("<p>Si puo' procedere con l'installazione /aggiornamento del software <b><i>Campo</i></b>. Premere il pulsante \"Next\".</p>");
break;
case 3:
strBody += wxT("<p>E' stato rilevata una chiave remota condivisa in rete con il servizio di gestione autorizzazioni:</p>");
strBody += wxT("<p align=center><img src=\"passerona.gif\" /></p>");
strBody += wxT("<p>Si puo' procedere con l'installazione /aggiornamento del software <b><i>Campo</i></b>. Premere il pulsante \"Next\".</p>");
break;
//griglia per sistemare i campi
wxGridBagSizer* gbsButtSizer = new wxGridBagSizer(VGAP, HGAP);
GetSizer()->Add(gbsButtSizer);
default:
strBody += wxT("<p><b>Non e' stata rilevata alcuna chiave hardware installata sul computer!</b></p>");
strBody += wxT("<p>Per procedere all'installazione della chiave hardware, <u>collegarla al computer e premere il bottone corrispondente</u> alla tipologia della chiave stessa per installarne i driver.</p>");
strBody += wxT("<p>Se si utilizza una chiave remota collegata ad un altro computer e condivisa in rete attraverso il servizio gestione di autorizzazioni ");
strBody += wxT("<u>indicare il nome del computer (o l'indirizzo IP) cui e' collegata la chiave e su cui e' <b>installato e funzionante</b> il gestore di autorizzazioni</u>. ");
//prima riga della griglia
//Hardlock label
AddLabel(gbsButtSizer, "Installa chiave locale di tipo Hardlock", 0, 0);
//Hardlock image
wxBitmap bmp_HL("../campo/servers/hardlock.gif", wxBITMAP_TYPE_GIF);
wxStaticBitmap* s_bmp_HL = new wxStaticBitmap(this, wxID_ANY, bmp_HL);
gbsButtSizer->Add(s_bmp_HL, wxGBPosition(0, 1));
//bottone Hardlock
wxButton* bHlButton = new wxButton(this, 401, wxT("Hardlock"), wxDefaultPosition, wxSize(64, -1));
gbsButtSizer->Add(bHlButton, wxGBPosition(0, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
//procedura per la costruzione dei bottoni e delle immagini per l'installazione dei driver di chiave
//"griglia" contenitrice degli oggetti
//seconda riga della griglia
//Eutron label
AddLabel(gbsButtSizer, "Installa chiave locale di tipo Eutron", 1, 0);
//Eutron image
wxBitmap bmp_EU("../campo/servers/eutron.gif", wxBITMAP_TYPE_GIF);
wxStaticBitmap* s_bmp_EU = new wxStaticBitmap(this, wxID_ANY, bmp_EU);
gbsButtSizer->Add(s_bmp_EU, wxGBPosition(1, 1));
//bottone Eutron
wxButton* bEuButton = new wxButton(this, 402, wxT("Eutron"), wxDefaultPosition, wxSize(64, -1));
gbsButtSizer->Add(bEuButton, wxGBPosition(1, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
//griglia per sistemare i campi
wxGridBagSizer* gbsButtSizer = new wxGridBagSizer(VGAP, HGAP);
GetSizer()->Add(gbsButtSizer);
//prima riga della griglia
//Hardlock label
AddLabel(gbsButtSizer, "Installa chiave locale di tipo Hardlock", 0, 0);
//Hardlock image
wxBitmap bmp_HL("hardlock.gif", wxBITMAP_TYPE_GIF);
wxStaticBitmap* s_bmp_HL = new wxStaticBitmap(this, wxID_ANY, bmp_HL);
gbsButtSizer->Add(s_bmp_HL, wxGBPosition(0, 1));
//bottone Hardlock
wxButton* bHlButton = new wxButton(this, 401, wxT("Hardlock"), wxDefaultPosition, wxSize(64, -1));
gbsButtSizer->Add(bHlButton, wxGBPosition(0, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
//seconda riga della griglia
//Eutron label
AddLabel(gbsButtSizer, "Installa chiave locale di tipo Eutron", 1, 0);
//Eutron image
wxBitmap bmp_EU("eutron.gif", wxBITMAP_TYPE_GIF);
wxStaticBitmap* s_bmp_EU = new wxStaticBitmap(this, wxID_ANY, bmp_EU);
gbsButtSizer->Add(s_bmp_EU, wxGBPosition(1, 1));
//bottone Eutron
wxButton* bEuButton = new wxButton(this, 402, wxT("Eutron"), wxDefaultPosition, wxSize(64, -1));
gbsButtSizer->Add(bEuButton, wxGBPosition(1, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
//terza riga della griglia
//Server label
AddLabel(gbsButtSizer, "Nome o indirizzo IP del server di autorizzazioni", 2, 0);
//Server image
/* wxBitmap bmp_Srv("passerona.gif", wxBITMAP_TYPE_GIF);
wxStaticBitmap* s_bmp_Srv = new wxStaticBitmap(this, wxID_ANY, bmp_Srv);
gbsButtSizer->Add(s_bmp_Srv, wxGBPosition(2, 1));*/
//nome Server
wxTextCtrl* tcSrvName = new wxTextCtrl(this, 403, "", wxDefaultPosition, wxSize(320,-1));
gbsButtSizer->Add(tcSrvName, wxGBPosition(2, 2));
break;
}
//terza riga della griglia
//Server label
AddLabel(gbsButtSizer, "Nome o indirizzo IP del server di autorizzazioni", 2, 0);
//Server image
wxBitmap bmp_Srv("../campo/servers/autho.gif", wxBITMAP_TYPE_GIF);
wxStaticBitmap* s_bmp_Srv = new wxStaticBitmap(this, wxID_ANY, bmp_Srv);
gbsButtSizer->Add(s_bmp_Srv, wxGBPosition(2, 1));
//nome Server
wxTextCtrl* tcSrvName = new wxTextCtrl(this, 403, "", wxDefaultPosition, wxSize(320,-1));
gbsButtSizer->Add(tcSrvName, wxGBPosition(2, 2));
SetHTMLText(strTitle, strBody);
//aggiorna il tipo di chiave per poterlo scrivere sul campo.ini
GetWizard().SetDongleType(_dongle_type);
}
/**********************************************************************************************************/
@ -1939,8 +1783,8 @@ CampoWizard::CampoWizard(wxWindow* pParent)
Create(pParent, wxID_ANY, APPNAME, bitmap);
m_pPage[0] = new CampoWizardPage1(this); //benvenuto con logo
m_pPage[1] = new CampoWizardPage2(this); //scelta aggiornamento/tipo installazione
m_pPage[2] = new CampoWizardPage3(this); //licenza
m_pPage[1] = new CampoWizardPage2(this); //licenza
m_pPage[2] = new CampoWizardPage3(this); //scelta aggiornamento/tipo installazione
m_pPage[3] = new CampoWizardPage4(this); //test ed installazione chiavi
m_pPage[4] = new CampoWizardPage5(this); //selezione tipo installazione
m_pPage[5] = new CampoWizardPage6(this); //installazione standard

210
setup/setupkey.cpp Executable file
View File

@ -0,0 +1,210 @@
#include "wxinc.h"
#include <wx/socket.h>
#include "setupkey.h"
extern "C"
{
#include "../xvaga/hlapi_c.h"
#include "../xvaga/skeylink.h"
}
///////////////////////////////
// Utilities //
///////////////////////////////
bool ErrorBox(const wxString str)
{
wxMessageBox(str, APPNAME, wxOK | wxICON_ERROR);
return false;
}
bool WarningBox(const wxString str)
{
wxMessageBox(str, APPNAME, wxOK | wxICON_EXCLAMATION);
return false;
}
static int ThisYear()
{
int anno = 2006;
time_t lt;
if (time(&lt) == 0)
{
struct tm* timeloc = localtime(&lt) ;
if (timeloc != NULL)
anno = timeloc->tm_year + 1900;
}
return anno;
}
///////////////////////////////
// Gestione chiave Hardlock //
///////////////////////////////
bool HardlockGarble(unsigned short* data)
{
HL_CODE(data, 1);
return true;
}
unsigned short HardlockLogin(int& year)
{
unsigned short serno = 0xFFFF;
unsigned char REFKEY[16] = "CAMPOKEY";
unsigned char VERKEY[16] = "ìpÙˆ¬cê<";
if (HL_LOGIN(26952, LOCAL_DEVICE, REFKEY, VERKEY) == STATUS_OK)
{
unsigned short eprom[64]; memset(eprom, 0, sizeof(eprom));
HL_READBL((unsigned char*)eprom);
unsigned short data[4];
memcpy(data, eprom, sizeof(data));
HardlockGarble(data);
if (data[0] == 0xFAE8)
serno = data[1];
else
serno = 0;
memcpy(data, &eprom[60], sizeof(data));
if (HardlockGarble(data))
year = (int)data[0];
}
return serno;
}
///////////////////////////////
// Gestione chiave Eutron //
///////////////////////////////
void EncodeEutronPassword(char* str)
{
const char* const key = "QSECOFR-";
char tmp[16];
int i;
for (i = 0; str[i]; i++)
tmp[i] = str[i] + (i < 8 ? key[i] : str[i - 8]);
tmp[i] = '\0';
strcpy(str, tmp);
}
unsigned short EutronLogin(int& year)
{
unsigned short serno = 0xFFFF;
const char* const login[2] = { "AGA.CAMPO", "25EBAI" };
for (int i = 0; i < 2; i++)
{
KEY_NET eutron_key;
memset(&eutron_key, 0, sizeof(KEY_NET));
eutron_key.net_command = NET_KEY_OPEN;
eutron_key.command = LOCATING_MODE;
const char* const chiaro = login[i];
char cifrato[16];
strcpy(cifrato, chiaro);
EncodeEutronPassword(cifrato);
memset(eutron_key.label, 0, LABEL_LENGTH);
strcpy((char*)eutron_key.label, chiaro);
memset(eutron_key.password, 0, PASSWORD_LENGTH);
strcpy((char*)eutron_key.password, cifrato);
smartlink(&eutron_key);
if (eutron_key.status == ST_OK)
{
eutron_key.net_command = NET_KEY_ACCESS;
eutron_key.command = BLOCK_READING_MODE;
short* pointer = (short*)(&eutron_key.data[0]);
short* number = (short*)(&eutron_key.data[2]);
*pointer = 0; // Posizione in cui leggere
*number = 8; // Words da leggere
smartlink(&eutron_key);
if (eutron_key.status == ST_OK)
{
serno = (unsigned short)atol((const char*)eutron_key.data+4);
if (i == 0)
{
const unsigned short y = *(unsigned short*)(eutron_key.data+12);
if (y > 2000 && y < 3000)
year = y;
}
else
year = ThisYear();
break;
}
}
}
return serno;
}
//////////////////////////////////
// Gestione Server di chiavi //
//////////////////////////////////
static unsigned short InquireSocketNumber(wxSocketClient& sc, const wxString& strCommand)
{
sc.Write(strCommand, (wxUint32)strCommand.Len());
long number[2] = { 0L, 0L };
sc.Read(number, sizeof(number));
return (unsigned short)number[1];
}
static unsigned short InquireServer(const wxString& strSrvName, int& year, const bool bMsg)
{
wxIPV4address ip;
if (!ip.Hostname(strSrvName) || !ip.Service("1883")) //indirizzo NON valido o porta scazzata!
{
if (bMsg)
ErrorBox("Indirizzo IP errato!");
return 0xFFFF;
}
wxSocketClient sc;
if (!sc.Connect(ip)) //il computer remoto risponde ma il server no (non c'e' o e' spento)
{
if (bMsg)
ErrorBox("Il server specificato non e' raggiungibile!");
return 0xFFFF;
}
unsigned short serno = InquireSocketNumber(sc, "DongleNumber()");
year = InquireSocketNumber(sc, "DongleYear()");
return serno;
}
unsigned short ServerLogin(int& year, wxString& strSrvName)
{
unsigned short serno = 0xFFFF;
//se non specificato un nome/indirizzo di server, lo cerca tra i miei "cpu fratelli" in rete
if (strSrvName.IsEmpty())
{
//intanto deve trovare il suo IP di rete
wxIPV4address ip;
ip.AnyAddress();
wxString strMyName = ip.Hostname();
ip.Hostname(strMyName);
wxString strMyIP = ip.IPAddress();
wxString strSrvIP;
for (int i = 9; i < 256; i++)
{
//deve sostituire l'ultima cifra dell'IP con tutti i numeri che vanno da 0 a 255 alla ricerca del server
strSrvIP = strMyIP.BeforeLast('.');
strSrvIP << "." << i;
serno = InquireServer(strSrvIP, year, false);
if (serno != 0xFFFF)
{
ip.Hostname(strSrvIP);
strSrvName = ip.Hostname();
break;
}
}
}
else //se invece e' specificato un server vede se il server di chiavi c'e' e funziona davvero
{
serno = InquireServer(strSrvName, year, true);
}
return serno;
}

15
setup/setupkey.h Executable file
View File

@ -0,0 +1,15 @@
#ifndef __SETUPKEY_H
#define __SETUPKEY_H
bool ErrorBox(const wxString str);
bool WarningBox(const wxString str);
bool HardlockGarble(unsigned short* data);
unsigned short HardlockLogin(int& year);
void EncodeEutronPassword(char* str);
unsigned short EutronLogin(int& year);
unsigned short ServerLogin(int& year, wxString& strSrvName);
#endif