diff --git a/setup/Setup.cpp b/setup/Setup.cpp index e3d966c0c..7148d6a06 100755 --- a/setup/Setup.cpp +++ b/setup/Setup.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -605,15 +606,13 @@ CampoWizardPage3::CampoWizardPage3(wxWizard* parent) : CampoWizardPage(parent) class CampoWizardPage4 : public CampoWizardPage { int _dongle_type; - wxButton* _butt_HL; - wxButton* _butt_EU; protected: DECLARE_EVENT_TABLE(); void OnHLPick(wxCommandEvent& e); void OnEUPick(wxCommandEvent& e); - int DongleTest(); + int DongleTest(const wxString& strSrvName = wxEmptyString); int ThisYear(); wxString DecodeString(const wxString& data); int VersionYear(); @@ -625,6 +624,10 @@ protected: 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); }; @@ -745,6 +748,54 @@ unsigned short CampoWizardPage4::EutronLogin(int& year) 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; + } + + unsigned short serno = InquireSocketNumber(sc, "DongleNumber()"); + year = InquireSocketNumber(sc, "DongleYear()"); + + return serno; +} + +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 // ///////////////////////////////////////////////////////// @@ -788,25 +839,46 @@ int CampoWizardPage4::VersionYear() return atoi(ver); } -int CampoWizardPage4::DongleTest() +int CampoWizardPage4::DongleTest(const wxString& strSrvName) { _dongle_type = 0; int yearKey = 0; - unsigned int serno = HardlockLogin(yearKey); + unsigned int serno = 0xFFFF; + + if (!strSrvName.IsEmpty()) + { + serno = ServerLogin(yearKey, strSrvName); + if (serno != 0xFFFF) + _dongle_type = 3; //chiave remota + } + if (serno == 0xFFFF) - { - serno = EutronLogin(yearKey); - if (serno != 0xFFFF) - _dongle_type = 2; //chiave eutron - } - else - _dongle_type = 1; //chiave hardlock - + { + serno = HardlockLogin(yearKey); + if (serno == 0xFFFF) + { + serno = EutronLogin(yearKey); + if (serno != 0xFFFF) + _dongle_type = 2; //chiave eutron + else + { + if (strSrvName.IsEmpty()) + { + serno = ServerLogin(yearKey, strSrvName); + if (serno != 0xFFFF) + _dongle_type = 3; //chiave remota + } + } + } + else + _dongle_type = 1; //chiave hardlock + } + if (serno == 0) // Chiave di sviluppo 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 @@ -874,32 +946,58 @@ CampoWizardPage4::CampoWizardPage4(wxWizard* parent) : CampoWizardPage(parent) strBody += wxT("

"); strBody += wxT("

Si puo' procedere con l'installazione /aggiornamento del software Campo. Premere il pulsante \"Next\".

"); break; - //case 3: e' il caso del server di chiavi;la DongleTest() per ora non lo fa - //break; + case 3: + strBody += wxT("

E' stato rilevata una chiave remota condivisa in rete con il servizio di gestione autorizzazioni:

"); + strBody += wxT("

"); + strBody += wxT("

Si puo' procedere con l'installazione /aggiornamento del software Campo. Premere il pulsante \"Next\".

"); + break; + default: - strBody += wxT("

Non e' stata rilevata alcuna chiave hardware installata !

"); - strBody += wxT("

Per procedere all'installazione dei driver della chiave hardware collegata al computer premere il bottone corrispondente alla tipologia della chiave stessa.

"); - strBody += wxT("

Se si desidera proseguire nell'installazione del software senza installare la chiave hardware cliccare su \"Next\".

"); - strBody += wxT("

Quest'ultima procedura e' consigliata solo in caso di installazione tipo Client di rete senza chiave propria, ma che utilizza un server di autorizzazioni gia' installato e funzionante in rete.

"); + strBody += wxT("

Non e' stata rilevata alcuna chiave hardware installata sul computer!

"); + strBody += wxT("

Per procedere all'installazione della chiave hardware, collegarla al computer e premere il bottone corrispondente alla tipologia della chiave stessa per installarne i driver.

"); + strBody += wxT("

Se si utilizza una chiave remota collegata ad un altro computer e condivisa in rete attraverso il servizio gestione di autorizzazioni "); + strBody += wxT("indicare il nome del computer (o l'indirizzo IP) cui e' collegata la chiave e su cui e' installato e funzionante il gestore di autorizzazioni. "); //procedura per la costruzione dei bottoni e delle immagini per l'installazione dei driver di chiave //"griglia" contenitrice degli oggetti - wxBoxSizer* butt_box = new wxBoxSizer(wxHORIZONTAL); - GetSizer()->Add(butt_box, 0, wxALIGN_CENTER_HORIZONTAL, 0); - //Hardlock img e button + + //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); - butt_box->Add(s_bmp_HL, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); - _butt_HL = new wxButton(this, 401, "Hardlock", wxDefaultPosition, wxSize(100, 50)); - butt_box->Add(_butt_HL, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); - //spaziatore centrale - butt_box->AddSpacer(24); - //Eutron img e button - _butt_EU = new wxButton(this, 402, "Eutron", wxDefaultPosition, wxSize(100, 50)); - butt_box->Add(_butt_EU, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); + 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); - butt_box->Add(s_bmp_EU, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 8); + 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; }