diff --git a/setup/Setup.cpp b/setup/Setup.cpp index 79a2ec490..606b8002b 100755 --- a/setup/Setup.cpp +++ b/setup/Setup.cpp @@ -596,6 +596,8 @@ protected: DECLARE_EVENT_TABLE(); void OnHLPick(wxCommandEvent& e); void OnEUPick(wxCommandEvent& e); + void OnSRPick(wxCommandEvent& e); + virtual bool ForwardValidate(); virtual bool TransferDataToWindow(); @@ -612,6 +614,7 @@ public: BEGIN_EVENT_TABLE(CampoWizardPage4, CampoWizardPage) EVT_BUTTON(401, OnHLPick) EVT_BUTTON(402, OnEUPick) + EVT_BUTTON(403, OnSRPick) END_EVENT_TABLE() void CampoWizardPage4::OnHLPick(wxCommandEvent& e) @@ -626,12 +629,22 @@ void CampoWizardPage4::OnEUPick(wxCommandEvent& e) wxExecute(path, wxEXEC_SYNC); } +void CampoWizardPage4::OnSRPick(wxCommandEvent& e) +{ + wxString strSrvName; + int year = 0; + unsigned short serno = ServerLogin(year, strSrvName); + if (!strSrvName.IsEmpty()) + Set(404, strSrvName); +} + bool CampoWizardPage4::ForwardValidate() { /* int serno = 0xFFFF; - if (Get(403) != "") + if (Get(404) != "") { - serno = ServerLogin(0, Get(403)); + int year; + serno = ServerLogin(year, Get(404)); } if (serno == 0xFFFF) return ErrorBox("Impossibile trovare la chiave in rete!!");*/ @@ -644,6 +657,7 @@ bool CampoWizardPage4::TransferDataToWindow() FindWindowById(401)->Disable(); FindWindowById(402)->Disable(); FindWindowById(403)->Disable(); + FindWindowById(404)->Disable(); //controlla preventivamente se la chiave c'e' ed eventualmente quale e' (hardlock,eutron,server di chiavi) const int nDongleType = DongleTest(); @@ -667,17 +681,19 @@ bool CampoWizardPage4::TransferDataToWindow() strBody += wxT("
E' stato rilevata una chiave remota condivisa in rete con il servizio di gestione autorizzazioni:
"); strBody += wxT("Si puo' procedere con l'installazione /aggiornamento del software Campo. Premere il pulsante \"Next\".
"); - Set(403, GetWizard().GetSrvAuth()); + Set(404, GetWizard().GetSrvAuth()); break; default: 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. "); + strBody += wxT("premere il bottone Cerca per attivare la ricerca automatica della chiave remota. Qualora tale ricerca fallisse digitare il nome del computer "); + strBody += wxT("(o l'indirizzo IP) cui e' collegata la chiave di rete e su cui e' installato e funzionante il gestore di autorizzazioni. "); FindWindowById(401)->Enable(); FindWindowById(402)->Enable(); FindWindowById(403)->Enable(); + FindWindowById(404)->Enable(); break; } @@ -715,12 +731,12 @@ int CampoWizardPage4::VersionYear() int CampoWizardPage4::DongleTest() { - wxString strSrvName = GetWizard().GetSrvAuth(); //nome del server di autorizzazioni (se c'e') int dongle_type = 0; int yearKey = 0; unsigned int serno = 0xFFFF; + wxString strSrvName = GetWizard().GetSrvAuth(); //nome del server di autorizzazioni (se c'e') if (!strSrvName.IsEmpty()) { serno = ServerLogin(yearKey, strSrvName); @@ -736,18 +752,6 @@ int CampoWizardPage4::DongleTest() 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 - GetWizard().SetSrvAuth(strSrvName); - } - } - } } else dongle_type = 1; //chiave hardlock @@ -840,14 +844,13 @@ CampoWizardPage4::CampoWizardPage4(wxWizard* parent) : CampoWizardPage(parent) //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)); - + wxTextCtrl* tcSrvName = new wxTextCtrl(this, 404, "", wxDefaultPosition, wxSize(128,-1)); + gbsButtSizer->Add(tcSrvName, wxGBPosition(2, 1)); + //bottone Eutron + wxButton* bSrvButton = new wxButton(this, 403, wxT("Cerca"), wxDefaultPosition, wxSize(64, -1)); + gbsButtSizer->Add(bSrvButton, wxGBPosition(2, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); + } /**********************************************************************************************************/ diff --git a/setup/setupkey.cpp b/setup/setupkey.cpp index 7b9ae877d..24c6574a6 100755 --- a/setup/setupkey.cpp +++ b/setup/setupkey.cpp @@ -177,34 +177,54 @@ static unsigned short InquireServer(const wxString& strSrvName, int& year, const 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++) + wxIPV4address ipLocal; + ipLocal.AnyAddress(); + wxString strMyName = ipLocal.Hostname(); + ipLocal.Hostname(strMyName); + const wxString strMyIP = ipLocal.IPAddress(); + + if (strMyIP.Len() > 7) { - //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) + wxSocketClient sc[256]; + for (int i = 0; i < 256; i++) { - ip.Hostname(strSrvIP); - strSrvName = ip.Hostname(); - break; + //deve sostituire l'ultima cifra dell'IP con tutti i numeri che vanno da 0 a 255 alla ricerca del server + wxString strSrvIP = strMyIP.BeforeLast('.'); + strSrvIP << "." << i; + wxIPV4address ipRemote; + if (ipRemote.Hostname(strSrvIP) && ipRemote.Service("1883")) + { + sc[i].SetTimeout(2); + sc[i].Connect(ipRemote, false); + } } + wxSleep(2); + for (int i = 0; i < 256; i++) + { + sc[i].WaitOnConnect(0, 10); + if (sc[i].IsConnected()) + { + wxIPV4address ipRemote; + sc[i].GetPeer(ipRemote); + strSrvName = ipRemote.Hostname(); + serno = InquireSocketNumber(sc[i], "DongleNumber()"); + year = InquireSocketNumber(sc[i], "DongleYear()"); + if (year > 0) + break; + } + } + + for (int i = 0; i < 256; i++) + sc[i].Destroy(); } } - else //se invece e' specificato un server vede se il server di chiavi c'e' e funziona davvero - { + else serno = InquireServer(strSrvName, year, true); - } return serno; }