2012-03-20 13:37:23 +00:00
|
|
|
#include "wxinc.h"
|
|
|
|
#include "xvt.h"
|
|
|
|
|
2012-04-13 15:14:01 +00:00
|
|
|
#include "wx/filename.h"
|
|
|
|
|
2012-03-23 09:53:09 +00:00
|
|
|
#include "../ssa/h/ssadll.h"
|
|
|
|
#include "../ssa/h/ssaerr.h"
|
2012-03-20 13:37:23 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSSA_Pinger
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TSSA_Pinger : public wxTimer
|
|
|
|
{
|
|
|
|
int m_nSerNo;
|
|
|
|
bool m_bRemote;
|
|
|
|
wxString m_strModule;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Notify();
|
|
|
|
|
|
|
|
bool IsRemote() const { return m_bRemote; }
|
|
|
|
bool IsMenu() const;
|
|
|
|
|
|
|
|
int AddRef(const wxString& m, int nDelta = +1);
|
|
|
|
int DecRef(const wxString& m) { return AddRef(m, -1); }
|
|
|
|
|
|
|
|
wxString NormalizedModule(const char* m) const;
|
|
|
|
bool LoginProduct();
|
|
|
|
bool LogoutProduct();
|
|
|
|
const char* UserId() const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
int Login(const char* module);
|
|
|
|
int Serial() const { return m_nSerNo; }
|
|
|
|
int Logout(const char* module);
|
|
|
|
TSSA_Pinger();
|
|
|
|
};
|
|
|
|
|
|
|
|
static TSSA_Pinger* _ssa_timer = NULL;
|
2012-10-26 09:10:17 +00:00
|
|
|
static const char* const _ssa_product = "CAMPO";
|
2014-12-22 08:56:07 +00:00
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
const char* TSSA_Pinger::UserId() const
|
2012-03-20 13:37:23 +00:00
|
|
|
{
|
2015-06-17 07:17:35 +00:00
|
|
|
static char id[256] = { 0 };
|
2012-03-20 13:37:23 +00:00
|
|
|
if (!*id)
|
|
|
|
{
|
|
|
|
const int sess = xvt_sys_get_session_id();
|
2014-12-22 08:56:07 +00:00
|
|
|
char user[64], host[64];
|
2012-03-20 13:37:23 +00:00
|
|
|
xvt_sys_get_user_name(user, sizeof(user));
|
|
|
|
xvt_sys_get_host_name(host, sizeof(host));
|
2014-12-22 08:56:07 +00:00
|
|
|
sprintf_s(id, sizeof(id), "%s@%s:%d", user, host, sess);
|
2012-03-20 13:37:23 +00:00
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
bool TSSA_Pinger::IsMenu() const
|
2012-04-13 15:14:01 +00:00
|
|
|
{
|
2012-04-24 10:28:43 +00:00
|
|
|
const wxFileName argv0 = __argv[0];
|
2015-06-17 07:17:35 +00:00
|
|
|
return argv0.GetName().IsSameAs("ba0", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TSSA_Pinger::Notify()
|
|
|
|
{ SSA_Ping(UserId()); }
|
|
|
|
|
|
|
|
bool TSSA_Pinger::LoginProduct()
|
|
|
|
{
|
|
|
|
bool bLoggedIn = IsRemote() && !IsMenu();
|
|
|
|
if (!bLoggedIn)
|
2012-04-24 10:28:43 +00:00
|
|
|
{
|
2015-06-17 07:17:35 +00:00
|
|
|
const int err = SSA_Login(UserId(), _ssa_product);
|
|
|
|
bLoggedIn = err == 0;
|
2012-04-24 10:28:43 +00:00
|
|
|
}
|
2015-06-17 07:17:35 +00:00
|
|
|
if (bLoggedIn && m_nSerNo < 0)
|
|
|
|
m_nSerNo = SSA_NumeroSerie(_ssa_product);
|
|
|
|
|
|
|
|
if (bLoggedIn && IsRemote() && IsMenu())
|
|
|
|
::WritePrivateProfileSection(UserId(), "\0\0", "./ssa.ini"); // Azzera tutti i conteggi dei moduli
|
|
|
|
|
|
|
|
return bLoggedIn;
|
2012-04-13 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
bool TSSA_Pinger::LogoutProduct()
|
|
|
|
{
|
|
|
|
m_nSerNo = SSA_UTENTE_NON_LOGGATO;
|
|
|
|
if (IsRemote() && !IsMenu())
|
|
|
|
return true;
|
|
|
|
int err = SSA_Logout(UserId(), _ssa_product);
|
|
|
|
return err == 0;
|
|
|
|
}
|
2012-04-13 15:14:01 +00:00
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
wxString TSSA_Pinger::NormalizedModule(const char* m) const
|
2012-04-13 15:14:01 +00:00
|
|
|
{
|
2015-06-17 07:17:35 +00:00
|
|
|
wxString module;
|
|
|
|
if (m && *m)
|
|
|
|
{
|
|
|
|
module = m;
|
|
|
|
module.Trim();
|
|
|
|
module.MakeLower();
|
|
|
|
module.Truncate(2);
|
|
|
|
}
|
|
|
|
return module;
|
|
|
|
}
|
2012-04-13 15:14:01 +00:00
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
int TSSA_Pinger::AddRef(const wxString& module, int nDelta)
|
|
|
|
{
|
|
|
|
int nCount = xvt_sys_get_profile_int("./ssa.ini", UserId(), module, 0);
|
|
|
|
nCount += nDelta;
|
|
|
|
if (nCount < 0) nCount = 0;
|
|
|
|
xvt_sys_set_profile_int("./ssa.ini", UserId(), module, nCount);
|
|
|
|
return nCount;
|
|
|
|
}
|
2012-04-13 15:14:01 +00:00
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
int TSSA_Pinger::Login(const char* mod)
|
|
|
|
{
|
|
|
|
if (mod == NULL || *mod == '\0')
|
|
|
|
return LoginProduct() ? Serial() : SSA_UTENTE_NON_LOGGATO;
|
2012-04-13 15:14:01 +00:00
|
|
|
|
2015-06-17 07:17:35 +00:00
|
|
|
const wxString module = NormalizedModule(mod);
|
|
|
|
if (module == "ba" || module == "pd" || module == "ps") // Base o personalizzazione
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IsRemote() && AddRef(module) > 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const char* uid = UserId();
|
|
|
|
int err = SSA_ApriModulo(uid, module);
|
|
|
|
if (err == SSA_UTENTE_NON_LOGGATO) // ritenta!
|
|
|
|
{
|
|
|
|
LoginProduct();
|
|
|
|
err = SSA_ApriModulo(uid, module);
|
|
|
|
}
|
|
|
|
if (err != 0 && *module >= 'a')
|
|
|
|
err = SSA_ApriModulo(uid, module.Upper());
|
|
|
|
|
|
|
|
if (IsRemote() && err != 0)
|
|
|
|
DecRef(module);
|
|
|
|
|
|
|
|
if (err == 0)
|
|
|
|
m_strModule = module;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TSSA_Pinger::Logout(const char* mod)
|
|
|
|
{
|
|
|
|
const wxString module = mod == NULL ? m_strModule : NormalizedModule(mod);
|
|
|
|
int err= 0;
|
|
|
|
bool cm = !module.IsEmpty() && module != "ba";
|
|
|
|
if (cm)
|
|
|
|
{
|
|
|
|
if (IsRemote())
|
|
|
|
cm = DecRef(module) <= 0;
|
|
|
|
if (cm)
|
|
|
|
err = SSA_ChiudiModulo(UserId(), module);
|
|
|
|
}
|
|
|
|
if (err == 0)
|
|
|
|
LogoutProduct();
|
|
|
|
return err;
|
|
|
|
}
|
2012-04-13 15:14:01 +00:00
|
|
|
|
|
|
|
TSSA_Pinger::TSSA_Pinger()
|
|
|
|
{
|
2015-06-17 07:17:35 +00:00
|
|
|
char ssaagent[128] = { 0 };
|
|
|
|
const int len = xvt_sys_get_profile_string("ssa.ini", "", "SSA-PORT", "", ssaagent, sizeof(ssaagent));
|
|
|
|
m_bRemote = len > 8;
|
|
|
|
m_nSerNo = -1;
|
2012-04-13 15:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// xvt_dongle_sa_...
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-20 13:37:23 +00:00
|
|
|
int xvt_dongle_sa_login(const char* module)
|
|
|
|
{
|
2015-06-17 07:17:35 +00:00
|
|
|
if (_ssa_timer == NULL)
|
|
|
|
_ssa_timer = new TSSA_Pinger;
|
|
|
|
return _ssa_timer->Login(module);
|
2012-03-20 13:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int xvt_dongle_sa_crypt(unsigned short* data)
|
|
|
|
{
|
2015-06-17 07:17:35 +00:00
|
|
|
if (_ssa_timer == NULL)
|
2012-03-20 13:37:23 +00:00
|
|
|
return SSA_UTENTE_NON_LOGGATO;
|
|
|
|
if (data == NULL)
|
|
|
|
return -EACCES;
|
2015-06-17 07:17:35 +00:00
|
|
|
|
2012-03-20 13:37:23 +00:00
|
|
|
data[0] ^= 0xDEAD;
|
|
|
|
data[1] ^= 0xBEEF;
|
|
|
|
data[2] ^= 0xDEAD;
|
|
|
|
data[3] ^= 0xBEEF;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xvt_dongle_sa_logout(const char* module)
|
|
|
|
{
|
|
|
|
int err = SSA_UTENTE_NON_LOGGATO;
|
2015-06-17 07:17:35 +00:00
|
|
|
if (_ssa_timer != NULL)
|
|
|
|
err = _ssa_timer->Logout(module); // logout
|
2012-03-20 13:37:23 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xvt_dongle_sa_test(const char* module)
|
|
|
|
{
|
2015-02-24 08:45:22 +00:00
|
|
|
int err = SSA_PROD_NOTFOUND;
|
2015-06-17 07:17:35 +00:00
|
|
|
if (module && *module && *module != '?')
|
2012-10-26 09:10:17 +00:00
|
|
|
{
|
2015-02-24 08:45:22 +00:00
|
|
|
wxString p = _ssa_product;
|
2012-10-26 09:10:17 +00:00
|
|
|
wxString m = module;
|
2015-02-24 08:45:22 +00:00
|
|
|
|
|
|
|
const int dot = m.Find('.');
|
|
|
|
if (dot > 0)
|
|
|
|
{
|
|
|
|
p = m.Left(dot);
|
|
|
|
m = m.Mid(dot+1);
|
|
|
|
}
|
|
|
|
err = SSA_VerificaModulo(p, m);
|
|
|
|
if (err <= SSA_MOD_NOTFOUND && m[0] >= 'a')
|
2012-10-26 09:10:17 +00:00
|
|
|
{
|
|
|
|
m.MakeUpper();
|
2015-02-24 08:45:22 +00:00
|
|
|
err = SSA_VerificaModulo(p, m);
|
2012-10-26 09:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 13:37:23 +00:00
|
|
|
return err;
|
|
|
|
}
|