2003-04-16 15:49:59 +00:00
|
|
|
|
#include <xvt.h>
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <dongle.h>
|
|
|
|
|
#include <isamrpc.h>
|
2006-12-13 16:22:33 +00:00
|
|
|
|
#include <modaut.h>
|
|
|
|
|
#include <scanner.h>
|
1998-02-13 13:46:18 +00:00
|
|
|
|
#include <utility.h>
|
2006-12-13 16:22:33 +00:00
|
|
|
|
#include <xvtility.h>
|
|
|
|
|
#include <urldefid.h>
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2003-04-30 15:46:08 +00:00
|
|
|
|
// Dongle stuff
|
1998-02-13 13:46:18 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#define USERADR 26952
|
|
|
|
|
#define AGAADR 26953
|
2003-04-30 15:46:08 +00:00
|
|
|
|
#define REFKEY (unsigned char*)"CAMPOKEY"
|
|
|
|
|
#define VERKEY (unsigned char*)"<22>pو<70>c<EFBFBD><"
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
2002-07-03 14:48:48 +00:00
|
|
|
|
#pragma pack(push, 1)
|
1998-05-28 10:09:12 +00:00
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
struct TEutronHeader
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
char _serno[8]; // 8
|
|
|
|
|
unsigned short _year_assist; // 10
|
|
|
|
|
unsigned short _max_users; // 12
|
|
|
|
|
unsigned long _last_date; // 16
|
|
|
|
|
unsigned long _scad_date; // 20
|
|
|
|
|
unsigned long _checksum; // 24
|
|
|
|
|
unsigned short _version; // 26
|
|
|
|
|
unsigned short _patch; // 28
|
|
|
|
|
unsigned short _offset_to_bits; // 30
|
|
|
|
|
unsigned short _size_of_bits; // 32
|
1998-02-13 13:46:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
struct TEutronFooter
|
|
|
|
|
{
|
|
|
|
|
unsigned long _size; // Should be sizeof(TEutronFooter)
|
|
|
|
|
unsigned long _checksum; // Much smarter position than header
|
|
|
|
|
unsigned long _filler1;
|
|
|
|
|
unsigned long _filler2;
|
|
|
|
|
unsigned long _filler3;
|
|
|
|
|
unsigned long _filler4;
|
|
|
|
|
unsigned long _filler5;
|
|
|
|
|
unsigned long _last_assist; // Last date of assistance query
|
|
|
|
|
unsigned long _assistance[MAX_DONGLE_ASSIST]; // Pre-payed assistance
|
|
|
|
|
|
|
|
|
|
unsigned long checksum(bool set);
|
|
|
|
|
bool valid();
|
|
|
|
|
TEutronFooter();
|
|
|
|
|
};
|
|
|
|
|
|
2002-07-03 14:48:48 +00:00
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
TEutronFooter::TEutronFooter()
|
|
|
|
|
{
|
|
|
|
|
const int s = sizeof(TEutronFooter);
|
|
|
|
|
memset(&_size, 0, s);
|
|
|
|
|
_size = s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long TEutronFooter::checksum(bool set)
|
|
|
|
|
{
|
|
|
|
|
if (set) _size = sizeof(TEutronFooter);
|
|
|
|
|
|
|
|
|
|
const word offset = sizeof(_size) + sizeof(_checksum);
|
|
|
|
|
byte* ptr = (byte*)(&_size) + offset;
|
|
|
|
|
const word len = word(_size - offset);
|
|
|
|
|
|
|
|
|
|
unsigned long cs = 0;
|
|
|
|
|
for (word i = 0; i < len; i++, ptr++)
|
2003-06-06 08:57:05 +00:00
|
|
|
|
cs += *ptr | ~(short(*ptr << 8));
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (set) _checksum = cs;
|
|
|
|
|
return cs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEutronFooter::valid()
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (_size == 0 || _checksum == 0)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
|
|
|
|
return _checksum == checksum(false);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Current dongle
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
static TDongle* _dongle = NULL;
|
|
|
|
|
|
|
|
|
|
TDongle& dongle()
|
|
|
|
|
{
|
|
|
|
|
if (_dongle == NULL)
|
|
|
|
|
_dongle = new TDongle;
|
|
|
|
|
return *_dongle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool destroy_dongle()
|
|
|
|
|
{
|
|
|
|
|
bool ok = _dongle != NULL;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
delete _dongle;
|
2003-04-30 15:46:08 +00:00
|
|
|
|
_dongle = NULL;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Bit helper functions
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
inline bool test_bit(word w, int b)
|
|
|
|
|
{
|
|
|
|
|
bool on = (w & (1 << b)) != 0;
|
|
|
|
|
return on;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
inline void set_bit(word& w, int b, bool on = true)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
if (on)
|
|
|
|
|
w |= 1 << b;
|
|
|
|
|
else
|
|
|
|
|
w &= ~(1 << b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void reset_bit(word& w, byte b)
|
|
|
|
|
{
|
|
|
|
|
w &= ~(1 << b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TDongle
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TDongle::TDongle()
|
|
|
|
|
: _hardware(_dongle_unknown), _type(_no_dongle), _serno(0xFFFF),
|
2009-05-20 15:36:38 +00:00
|
|
|
|
_max_users(1), _year_assist(2009), _dirty(false), _OEM(-1)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
memset(_eprom, 0, sizeof(_eprom));
|
1999-07-16 14:59:11 +00:00
|
|
|
|
memset(_assist, 0, sizeof(_assist));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDongle::~TDongle()
|
|
|
|
|
{
|
|
|
|
|
if (_serno != 0xFFFF)
|
|
|
|
|
logout();
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TString& TDongle::administrator(TString* pwd) const
|
1999-03-22 15:55:50 +00:00
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
|
if (_admin.blank())
|
2009-05-20 15:36:38 +00:00
|
|
|
|
oem();
|
1999-03-22 15:55:50 +00:00
|
|
|
|
if (pwd)
|
|
|
|
|
*pwd = _admpwd;
|
|
|
|
|
return _admin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
// Data punta ad un array di 4 words
|
|
|
|
|
// Deve essere cosi' per problemi del C,
|
|
|
|
|
// non trasformare in array: pena di morte!
|
|
|
|
|
void TDongle::garble(word* data) const
|
|
|
|
|
{
|
|
|
|
|
switch (_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_crypt(data);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_sl_crypt(data);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::already_programmed() const
|
|
|
|
|
{
|
|
|
|
|
if (_hardware == _dongle_hardlock)
|
|
|
|
|
{
|
|
|
|
|
word data[4];
|
|
|
|
|
memcpy(data, &_eprom[60], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
|
|
|
|
|
if (data[0] < 1997 || data[0] > 2997)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
if (data[1] == 0 || data[1] >= 10000)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
const TDate today(TODAY);
|
2003-09-10 14:09:14 +00:00
|
|
|
|
const long giulio = *((const long*)&data[2]);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const long yyyymmdd = today.julian2date(giulio);
|
|
|
|
|
const TDate d(yyyymmdd);
|
|
|
|
|
if (d.year() < 1997 || d > today)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
} else
|
|
|
|
|
if (_hardware == _dongle_eutron)
|
|
|
|
|
{
|
|
|
|
|
const TEutronHeader* eh = (const TEutronHeader*)_eprom;
|
|
|
|
|
if (eh->_serno[0] == 0 || eh->_checksum == 0)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false; // Really virgin.
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
unsigned long cs = 0;
|
|
|
|
|
for (byte* ptr = (byte*)_eprom; ptr < (byte*)&eh->_checksum; ptr++)
|
2003-06-06 08:57:05 +00:00
|
|
|
|
cs += *ptr | ~(short(*ptr << 8));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (eh->_checksum != cs)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return false; // Malicious programming!
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
void TDongle::set_developer_permissions()
|
|
|
|
|
{
|
2009-02-03 09:14:30 +00:00
|
|
|
|
if (_serno == 0 && is_power_station())
|
|
|
|
|
{
|
|
|
|
|
_module.set(255); // Last module on key
|
|
|
|
|
_module.set(); // Activate all modules
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_module.reset(-1);
|
|
|
|
|
_module.set(0, true);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_shown.reset();
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
2007-03-16 13:33:09 +00:00
|
|
|
|
_year_assist = 3000;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
bool TDongle::hardlock_login(bool test_all_keys)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_type = _user_dongle;
|
|
|
|
|
if (test_all_keys)
|
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_logout();
|
|
|
|
|
if (xvt_dongle_hl_login(AGAADR, REFKEY, VERKEY))
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_type = _aga_dongle;
|
|
|
|
|
}
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_logout();
|
|
|
|
|
ok = xvt_dongle_hl_login(USERADR, REFKEY, VERKEY) != 0;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_hardware = _dongle_hardlock;
|
|
|
|
|
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_read_block((unsigned char*)_eprom);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
word data[4];
|
|
|
|
|
memcpy(data, _eprom, sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
|
|
|
|
|
if (data[0] == 0xFAE8)
|
|
|
|
|
_serno = data[1];
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-03-13 10:25:37 +00:00
|
|
|
|
if (data[0] == 0x3283 || data[0] == 0xA3AA) // chiave programmatori !!
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
1998-05-28 07:31:27 +00:00
|
|
|
|
if (_type == _user_dongle)
|
|
|
|
|
_type = _developer_dongle;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_serno = 0;
|
2007-12-10 09:48:34 +00:00
|
|
|
|
#ifdef DBG
|
|
|
|
|
if (test_all_keys && is_power_station())
|
|
|
|
|
_type = _aga_dongle;
|
|
|
|
|
#endif
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
|
|
|
|
_year_assist = _last_update.year();
|
|
|
|
|
|
2006-05-11 11:59:31 +00:00
|
|
|
|
if (_type == _user_dongle) //chiave cliente
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
const bool already = already_programmed();
|
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
_module.reset(); // Disattiva tutti i moduli
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_shown.reset();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const int last_word = already ? 12 : 4;
|
|
|
|
|
word data[4];
|
|
|
|
|
|
|
|
|
|
// Legge flag di attivazione dei moduli
|
|
|
|
|
for (int i = 0; i < last_word; i += 4)
|
|
|
|
|
{
|
|
|
|
|
memcpy(data, &_eprom[48+i], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
if (data[3] == _serno) // Validate block
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
|
{
|
|
|
|
|
word parola = data[j] ^ _serno;
|
|
|
|
|
if (parola)
|
|
|
|
|
{
|
|
|
|
|
for (int b = 15; b >= 0; b--)
|
|
|
|
|
{
|
|
|
|
|
if (test_bit(parola, b))
|
|
|
|
|
{
|
|
|
|
|
const word bit = i * 12 + j * 16 + b;
|
|
|
|
|
_module.set(bit+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_module.set(0, true); // Forza l'attivazione della base
|
1998-11-04 18:04:26 +00:00
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
// Legge anno di assitenza e numero massimo di utenti
|
|
|
|
|
memcpy(data, &_eprom[60], sizeof(data));
|
|
|
|
|
garble(data);
|
|
|
|
|
|
|
|
|
|
if (already)
|
|
|
|
|
{
|
|
|
|
|
_year_assist = data[0];
|
|
|
|
|
_max_users = data[1];
|
2003-09-23 14:47:55 +00:00
|
|
|
|
const long giulio = *((const long*)&data[2]);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const long yyyymmdd = _last_update.julian2date(giulio);
|
|
|
|
|
_last_update = yyyymmdd;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-06-25 10:41:20 +00:00
|
|
|
|
_year_assist = 0;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
else
|
|
|
|
|
set_developer_permissions();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_type = _no_dongle;
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::eutron_login(bool test_all_keys)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
2002-07-03 14:48:48 +00:00
|
|
|
|
|
2006-10-31 09:47:42 +00:00
|
|
|
|
const char* labels[3] = { "AGA.INFORMATICA", "AGA.CAMPO", "25EBAI" };
|
|
|
|
|
TDongleType types[3] = { _aga_dongle, _user_dongle, _developer_dongle };
|
|
|
|
|
for (int k = test_all_keys ? 0 : 1; k < 3; k++)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
const unsigned char* pwd = (const unsigned char*)::encode(labels[k]);
|
|
|
|
|
ok = xvt_dongle_sl_login((const unsigned char*)labels[k], pwd) != 0;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_hardware = _dongle_eutron;
|
|
|
|
|
_type = types[k];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_serno = 0;
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
|
|
|
|
_year_assist = _last_update.year();
|
|
|
|
|
|
2006-05-11 11:59:31 +00:00
|
|
|
|
if (_type == _user_dongle) //chiave cliente
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
1998-11-04 18:04:26 +00:00
|
|
|
|
_module.reset(); // Disattiva tutti i moduli
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (read_words(0, sizeof(TEutronHeader) / 2, _eprom))
|
|
|
|
|
{
|
|
|
|
|
const TEutronHeader* eh = (const TEutronHeader*)_eprom;
|
|
|
|
|
TString16 serno; serno.strncpy(eh->_serno, 8);
|
|
|
|
|
_serno = unsigned(atol(serno));
|
|
|
|
|
if (already_programmed())
|
|
|
|
|
{
|
|
|
|
|
_max_users = eh->_max_users;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
_last_update = eh->_last_date;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_year_assist = eh->_year_assist;
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
// Calcola il numero della word dove cominciano i bit di attivazione
|
|
|
|
|
unsigned short otb = eh->_offset_to_bits;
|
1999-07-21 09:18:16 +00:00
|
|
|
|
if (otb == 0) otb = 16; // Compatibile Hardlock
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
unsigned short sob = eh->_size_of_bits;
|
1999-07-21 09:18:16 +00:00
|
|
|
|
if (sob == 0) sob = 16; // Compatibile Hardlock
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
word data[64];
|
|
|
|
|
if (read_words(otb, sob, data))
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
int module = 1;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
for (word w = 0; w < sob; w++)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
for (int b = 0; b < 16; b++)
|
|
|
|
|
{
|
|
|
|
|
if (test_bit(data[w], b))
|
|
|
|
|
_module.set(module);
|
|
|
|
|
module++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
|
|
|
|
memset(_assist, 0, sizeof(_assist)); // Azzera pre-pagato
|
|
|
|
|
TEutronFooter ef;
|
|
|
|
|
if (read_words(otb+sob, sizeof(ef)/2, (word*)&ef))
|
|
|
|
|
{
|
|
|
|
|
if (ef.valid())
|
|
|
|
|
{
|
|
|
|
|
_last_assist = ef._last_assist;
|
|
|
|
|
memcpy(_assist, ef._assistance, sizeof(_assist));
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_module.set(0, true); // Forza l'attivazione della base
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
else
|
|
|
|
|
set_developer_permissions();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::network_login(bool test_all_keys)
|
|
|
|
|
{
|
2005-05-16 23:44:23 +00:00
|
|
|
|
const char* appname = main_app().name();
|
|
|
|
|
|
2004-03-31 12:48:16 +00:00
|
|
|
|
if (network() && ok())
|
2005-05-16 23:44:23 +00:00
|
|
|
|
rpc_UserLogout(appname);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
2010-02-17 12:15:28 +00:00
|
|
|
|
TString server = "127.0.0.1";
|
|
|
|
|
if (!xvt_sys_dongle_server_is_running())
|
|
|
|
|
server = ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
|
|
|
|
|
|
2004-03-31 12:48:16 +00:00
|
|
|
|
// const char* guest = "******";
|
|
|
|
|
// const TString16 appname = main_app().name();
|
|
|
|
|
// const char* utente = (!main_app().is_running() && appname == "ba0100") ? guest : (const char *) user();
|
|
|
|
|
const char* utente = user();
|
2002-12-18 10:56:10 +00:00
|
|
|
|
|
2010-02-17 12:15:28 +00:00
|
|
|
|
bool ok = rpc_UserLogin(server, utente, "******", appname);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
2010-02-17 12:15:28 +00:00
|
|
|
|
{
|
1998-02-13 13:46:18 +00:00
|
|
|
|
_hardware = _dongle_network;
|
|
|
|
|
_type = _user_dongle;
|
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
2010-02-17 12:15:28 +00:00
|
|
|
|
|
|
|
|
|
// Let's try to spare some network band!
|
|
|
|
|
ok = rpc_DongleInfo(_serno, _year_assist, _module);
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
_serno = rpc_DongleNumber();
|
|
|
|
|
_year_assist = rpc_DongleYear();
|
|
|
|
|
ok = rpc_DongleModules(_module);
|
2010-03-08 15:28:09 +00:00
|
|
|
|
if (ok && main_app().name() == "ba0100")
|
|
|
|
|
warning_box("ATTENZIONE! Il server di protezione non e' aggiornato:\n"
|
|
|
|
|
"Controllare la corretta installazione del servizio");
|
2010-02-17 12:15:28 +00:00
|
|
|
|
}
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1998-05-28 10:09:12 +00:00
|
|
|
|
int TDongle::can_try_server() const
|
|
|
|
|
{
|
2010-02-09 10:11:25 +00:00
|
|
|
|
// Se authoriz sta andando sono obbligato ad usarlo
|
2003-04-16 15:49:59 +00:00
|
|
|
|
if (xvt_sys_dongle_server_is_running())
|
1998-05-28 10:09:12 +00:00
|
|
|
|
return 3;
|
2010-02-09 10:11:25 +00:00
|
|
|
|
|
|
|
|
|
// Se sono un client ed ho l'indirizzo di authoriz sono obbligato ad usarlo
|
2009-05-20 15:36:38 +00:00
|
|
|
|
const TString& dongle = ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
|
2010-03-02 11:23:20 +00:00
|
|
|
|
if (dongle.full())
|
|
|
|
|
return ini_get_int(CONFIG_INSTALL, "Main", "Type") == 3 ? 3 : 1;
|
2010-02-09 10:11:25 +00:00
|
|
|
|
|
2010-03-02 11:23:20 +00:00
|
|
|
|
return false;
|
1998-05-28 10:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
bool TDongle::login(bool test_all_keys)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
if (_type != _no_dongle) // Already logged in
|
|
|
|
|
logout();
|
1998-05-28 10:09:12 +00:00
|
|
|
|
|
|
|
|
|
TDongleHardware hw = _hardware;
|
|
|
|
|
if (hw == _dongle_unknown)
|
|
|
|
|
{
|
2002-12-18 10:56:10 +00:00
|
|
|
|
if (can_try_server())
|
1998-05-28 10:09:12 +00:00
|
|
|
|
hw = _dongle_network;
|
|
|
|
|
else
|
2009-10-28 10:19:18 +00:00
|
|
|
|
hw = (TDongleHardware)ini_get_int(CONFIG_INSTALL, "Main", "Donglehw");
|
1998-05-28 10:09:12 +00:00
|
|
|
|
}
|
|
|
|
|
switch(hw)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
ok = hardlock_login(test_all_keys);
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
|
|
|
|
ok = eutron_login(test_all_keys);
|
|
|
|
|
break;
|
1998-06-23 14:30:08 +00:00
|
|
|
|
case _dongle_network:
|
1998-02-13 13:46:18 +00:00
|
|
|
|
ok = network_login(test_all_keys);
|
1998-05-28 10:09:12 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ok = false;
|
1998-05-28 10:09:12 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!ok)
|
1998-05-28 07:31:27 +00:00
|
|
|
|
{
|
|
|
|
|
// retry login for various dongles ...
|
2010-02-09 10:11:25 +00:00
|
|
|
|
const int should_use_server = can_try_server();
|
|
|
|
|
if (should_use_server != 3) // Non sono obbligato ad usare il Dongle Server
|
1998-05-28 10:09:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (!ok && hw != _dongle_eutron)
|
|
|
|
|
ok = eutron_login(test_all_keys);
|
|
|
|
|
if (!ok && hw != _dongle_hardlock)
|
|
|
|
|
ok = hardlock_login(test_all_keys);
|
|
|
|
|
}
|
2002-12-18 10:56:10 +00:00
|
|
|
|
|
|
|
|
|
if (ok)
|
2009-10-28 10:19:18 +00:00
|
|
|
|
ini_set_int(CONFIG_INSTALL, "Main", "Donglehw", (int)_hardware);
|
|
|
|
|
else
|
|
|
|
|
{ // DEMO
|
|
|
|
|
_hardware = _dongle_unknown;
|
|
|
|
|
_type = _no_dongle;
|
2010-03-08 15:31:20 +00:00
|
|
|
|
_serno = 0xFFFF; //numero di serie pi<70> alto possibile (65535 in exadecimals: non sar<61> mai raggiunto da chiavi clienti...magari!)
|
2009-10-28 10:19:18 +00:00
|
|
|
|
_max_users = 1;
|
|
|
|
|
_last_update = TDate(TODAY);
|
2010-03-08 15:31:20 +00:00
|
|
|
|
_year_assist = 3000; //anno di assistenza a 3000 per non avere problemi con le versioni nei vari anni
|
2009-10-28 10:19:18 +00:00
|
|
|
|
_module.set(ENDAUT); // Last module on key
|
|
|
|
|
_module.set(); // Activate all modules
|
|
|
|
|
_shown.reset();
|
1998-05-28 10:09:12 +00:00
|
|
|
|
}
|
1998-05-28 07:31:27 +00:00
|
|
|
|
}
|
2009-10-28 10:19:18 +00:00
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::logout()
|
|
|
|
|
{
|
2009-10-28 10:19:18 +00:00
|
|
|
|
switch (_hardware)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2009-10-28 10:19:18 +00:00
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
xvt_dongle_hl_logout();
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
|
|
|
|
xvt_dongle_sl_logout();
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_network:
|
|
|
|
|
rpc_UserLogout(main_app().name());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
_type = _no_dongle;
|
|
|
|
|
_serno = 0xFFFF;
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Data punta ad un array di 4 words
|
|
|
|
|
// Deve essere cosi' per problemi del C,
|
|
|
|
|
// non trasformare in array: pena di morte!
|
|
|
|
|
bool TDongle::read_words(word reg, word len, word* ud) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
switch (_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
{
|
|
|
|
|
for (word i = 0; i < len; i++)
|
2003-04-30 15:46:08 +00:00
|
|
|
|
xvt_dongle_hl_read(reg+i, &ud[i]);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ok = true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
while (len > 0)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
const unsigned short size = (len <= 16) ? len : 16;
|
|
|
|
|
ok = xvt_dongle_sl_read_block(reg, size, ud) != 0;
|
|
|
|
|
if (!ok)
|
1999-07-16 14:59:11 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
yesnofatal_box("EUTRON read error");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
len -= size;
|
|
|
|
|
reg += size;
|
|
|
|
|
ud += size;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Data punta ad un array di 4 words
|
|
|
|
|
// Deve essere cosi' per problemi del C,
|
|
|
|
|
// non trasformare in array: pena di morte!
|
|
|
|
|
bool TDongle::write_words(word reg, word len, word* data) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
switch(_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock:
|
|
|
|
|
{
|
|
|
|
|
for (word r = 0; r < len; r++)
|
|
|
|
|
{
|
|
|
|
|
const word address = reg+r;
|
2003-04-30 15:46:08 +00:00
|
|
|
|
ok = xvt_dongle_hl_write(address, data[r]) != 0;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case _dongle_eutron:
|
2003-04-30 15:46:08 +00:00
|
|
|
|
while (len > 0)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
{
|
2003-04-30 15:46:08 +00:00
|
|
|
|
const unsigned short size = (len <= 16) ? len : 16;
|
|
|
|
|
ok = xvt_dongle_sl_write_block(reg, size, data) != 0;
|
|
|
|
|
if (!ok)
|
|
|
|
|
break;
|
|
|
|
|
len -= size;
|
|
|
|
|
reg += size;
|
|
|
|
|
data += size;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
2003-04-30 15:46:08 +00:00
|
|
|
|
break;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-20 15:36:38 +00:00
|
|
|
|
int TDongle::oem() const
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
if (_OEM < 0)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-01-15 16:55:07 +00:00
|
|
|
|
TString& firm = (TString&) _reseller;
|
2009-01-15 15:08:18 +00:00
|
|
|
|
TString& campo = (TString&) _product;
|
2009-01-15 16:55:07 +00:00
|
|
|
|
TString& breve = (TString&) _shortname;
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TString& admin = (TString&)_admin;
|
|
|
|
|
TString& admpwd = (TString&)_admpwd;
|
|
|
|
|
int& oem = (int&)_OEM;
|
2009-01-12 15:24:09 +00:00
|
|
|
|
|
|
|
|
|
//nuovo metodo di rilevamento producer (dalla 10.0 in avanti); il producer sta nel file oem.ini sotto la cartella
|
|
|
|
|
//setup, sia nel CD che soprattutto nel programma installato
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TConfig ini(CONFIG_OEM, "MAIN");
|
|
|
|
|
oem = ini.get_int("OEM", NULL, -1, -1);
|
|
|
|
|
if (oem >= 0)
|
2009-01-12 15:24:09 +00:00
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TString8 para; para << "OEM_" << oem;
|
|
|
|
|
ini.set_paragraph(para);
|
|
|
|
|
campo = decode(ini.get("Product"));
|
|
|
|
|
firm = decode(ini.get("Reseller"));
|
|
|
|
|
breve = decode(ini.get("Name"));
|
|
|
|
|
admin = decode(ini.get("Administrator"));
|
|
|
|
|
admpwd = decode(ini.get("Password"));
|
2009-01-12 15:24:09 +00:00
|
|
|
|
}
|
2009-05-20 15:36:38 +00:00
|
|
|
|
|
2009-01-12 15:24:09 +00:00
|
|
|
|
if (firm.blank()) //vecchio metodo di rilevamento del producer: sta in install.ini
|
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
firm = decode(ini_get_string(CONFIG_GENERAL, "Main", "Producer"));
|
2009-01-15 16:55:07 +00:00
|
|
|
|
campo = breve = " ";
|
2009-01-12 15:24:09 +00:00
|
|
|
|
}
|
2009-01-15 15:08:18 +00:00
|
|
|
|
//nuovo metodo: cerca produttore (Name) e prodotto (Product)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (firm.blank())
|
|
|
|
|
{
|
|
|
|
|
ignore_xvt_errors(true);
|
|
|
|
|
char* p = firm.get_buffer(80);
|
|
|
|
|
xvt_res_get_str(STR_FIRMNAME, p, firm.size());
|
|
|
|
|
ignore_xvt_errors(false);
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-20 15:36:38 +00:00
|
|
|
|
if (admin.blank())
|
|
|
|
|
{
|
|
|
|
|
admin = decode(ini_get_string(CONFIG_GENERAL, "Main", "Administrator"));
|
|
|
|
|
if (admin.blank())
|
|
|
|
|
{
|
|
|
|
|
admin = "ADMIN";
|
|
|
|
|
admpwd = "ad.min";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (admpwd.blank())
|
|
|
|
|
{
|
|
|
|
|
admpwd = decode(ini_get_string(CONFIG_GENERAL, "Main", "Password"));
|
|
|
|
|
if (admpwd.blank())
|
|
|
|
|
{
|
|
|
|
|
admpwd = admin;
|
|
|
|
|
admpwd.lower();
|
|
|
|
|
admpwd.insert(".", 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 15:08:18 +00:00
|
|
|
|
if (campo.blank())
|
|
|
|
|
campo = "Campo Enterprise";
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (firm.blank())
|
2009-01-15 15:08:18 +00:00
|
|
|
|
firm = "AGA informatica s.r.l.";
|
2009-01-15 16:55:07 +00:00
|
|
|
|
if (breve.blank())
|
|
|
|
|
breve = "Campo";
|
2009-05-20 15:36:38 +00:00
|
|
|
|
|
|
|
|
|
if (oem < 0)
|
|
|
|
|
oem = firm.starts_with("AGA ") ? 0 : 1;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
2009-05-20 15:36:38 +00:00
|
|
|
|
return _OEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ritorna il nome della ditta che vende il programma attuale
|
|
|
|
|
const TString& TDongle::reseller() const
|
|
|
|
|
{
|
|
|
|
|
if (_reseller.empty())
|
|
|
|
|
oem();
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return _reseller;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 15:08:18 +00:00
|
|
|
|
const TString& TDongle::product() const
|
|
|
|
|
{
|
|
|
|
|
if (_product.empty())
|
2009-05-20 15:36:38 +00:00
|
|
|
|
oem();
|
2009-01-15 15:08:18 +00:00
|
|
|
|
return _product;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 10:11:25 +00:00
|
|
|
|
const TString& TDongle::short_name() const
|
2009-01-15 16:55:07 +00:00
|
|
|
|
{
|
|
|
|
|
if (_shortname.empty())
|
2009-05-20 15:36:38 +00:00
|
|
|
|
oem();
|
2009-01-15 16:55:07 +00:00
|
|
|
|
return _shortname;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-09 10:11:25 +00:00
|
|
|
|
const TString& TDongle::server_name() const
|
|
|
|
|
{
|
2010-02-17 12:15:28 +00:00
|
|
|
|
if (network() && !xvt_sys_dongle_server_is_running())
|
2010-02-09 10:11:25 +00:00
|
|
|
|
return ini_get_string(CONFIG_INSTALL, "Server", "Dongle");
|
|
|
|
|
|
|
|
|
|
TString& tmp = get_tmp_string(32);
|
|
|
|
|
xvt_sys_get_host_name(tmp.get_buffer(), tmp.size());
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool TDongle::active(word module) const
|
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
const bool yes = (module < ENDAUT) && _module[module] && shown(module);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return yes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::activate(word module, bool on)
|
|
|
|
|
{
|
|
|
|
|
bool ok = module < ENDAUT;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
_module.set(module, on && shown(module));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
bool TDongle::burn_hardlock()
|
|
|
|
|
{
|
|
|
|
|
word data[4];
|
|
|
|
|
|
|
|
|
|
const TDate today(TODAY);
|
|
|
|
|
const bool already = already_programmed();
|
|
|
|
|
if (already)
|
|
|
|
|
{
|
|
|
|
|
memcpy(data, &_eprom[60], sizeof(data));
|
|
|
|
|
garble(data);
|
2009-10-20 15:22:22 +00:00
|
|
|
|
if (data[0] < 2001 || data[0] > 3001)
|
1998-02-13 13:46:18 +00:00
|
|
|
|
return error_box("On Line Assistance error.");
|
|
|
|
|
if (data[1] == 0 || data[1] >= 10000)
|
|
|
|
|
return error_box("Bad users number.");
|
2003-09-23 14:47:55 +00:00
|
|
|
|
const long val = *((const long*)&data[2]);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
const long yyyymmdd = today.julian2date(val);
|
|
|
|
|
const TDate date(yyyymmdd);
|
|
|
|
|
if (date > today)
|
|
|
|
|
return error_box("Too late sir: key has already expired!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data[0] = _year_assist;
|
|
|
|
|
data[1] = _max_users;
|
2003-09-23 14:47:55 +00:00
|
|
|
|
long* val = (long*)&data[2];
|
|
|
|
|
*val = today.date2julian();
|
1998-02-13 13:46:18 +00:00
|
|
|
|
garble(data);
|
|
|
|
|
write_words(60, 4, data);
|
|
|
|
|
_last_update = today;
|
|
|
|
|
|
|
|
|
|
// Il primo bit della memoria della chiave corrisponde al modulo uno
|
|
|
|
|
// non allo zero (che e' la base ed e' sempre attivo)
|
|
|
|
|
word module = 1;
|
|
|
|
|
for (int octect = 0; octect < 3; octect++)
|
|
|
|
|
{
|
|
|
|
|
for(int parola = 0; parola < 3; parola++)
|
|
|
|
|
{
|
|
|
|
|
word& p = data[parola];
|
|
|
|
|
p = 0;
|
|
|
|
|
for (int bit = 0; bit < 16; bit++)
|
|
|
|
|
{
|
|
|
|
|
if (active(module))
|
|
|
|
|
set_bit(p, bit);
|
|
|
|
|
module++;
|
|
|
|
|
}
|
|
|
|
|
p ^= _serno;
|
|
|
|
|
}
|
|
|
|
|
data[3] = _serno;
|
|
|
|
|
garble(data);
|
|
|
|
|
write_words(48 + 4*octect, 4, data);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
return true;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::burn_eutron()
|
|
|
|
|
{
|
|
|
|
|
TEutronHeader* eh = (TEutronHeader*)_eprom;
|
|
|
|
|
memset(eh, 0, sizeof(TEutronHeader));
|
|
|
|
|
|
|
|
|
|
_last_update = TDate(TODAY);
|
1998-05-28 07:31:27 +00:00
|
|
|
|
sprintf(eh->_serno, "%lu", (unsigned long)_serno);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
eh->_year_assist = _year_assist;
|
|
|
|
|
eh->_max_users = _max_users;
|
|
|
|
|
eh->_last_date = atol(_last_update.string(ANSI));
|
|
|
|
|
eh->_scad_date = 0;
|
|
|
|
|
|
|
|
|
|
unsigned long cs = 0;
|
|
|
|
|
for (byte* ptr = (byte*)_eprom; ptr < (byte*)&eh->_checksum; ptr++)
|
2003-06-06 08:57:05 +00:00
|
|
|
|
cs += *ptr | ~(short(*ptr << 8));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
eh->_checksum = cs;
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const word otb = sizeof(TEutronHeader) / 2;
|
|
|
|
|
const word sob = 16;
|
|
|
|
|
eh->_offset_to_bits = otb;
|
|
|
|
|
eh->_size_of_bits = sob;
|
|
|
|
|
|
|
|
|
|
bool ok = write_words(0, otb, _eprom);
|
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
word data[sob]; memset(data, 0, sizeof(data));
|
1998-02-13 13:46:18 +00:00
|
|
|
|
for (int module = 1; module < 256; module++)
|
|
|
|
|
{
|
|
|
|
|
if (active(module))
|
|
|
|
|
{
|
|
|
|
|
word& w = data[(module-1) / 16];
|
2006-12-13 16:22:33 +00:00
|
|
|
|
set_bit(w, (module-1) % 16, true);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = write_words(otb, sob, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
TEutronFooter ef;
|
|
|
|
|
CHECK(sizeof(ef._assistance) == sizeof(_assist), "Assistance size mismatch");
|
|
|
|
|
ef._last_assist = _last_assist.year()*10000L + _last_assist.month()*100L + _last_assist.day();
|
|
|
|
|
memcpy(ef._assistance, _assist, sizeof(_assist));
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ef.checksum(true);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = write_words(otb+sob, word(ef._size/2), (word*)&ef);
|
1998-02-13 13:46:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::burn()
|
|
|
|
|
{
|
|
|
|
|
bool ok = local() && _type == _user_dongle;
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
switch(_hardware)
|
|
|
|
|
{
|
|
|
|
|
case _dongle_hardlock: ok = burn_hardlock(); break;
|
|
|
|
|
case _dongle_eutron : ok = burn_eutron(); break;
|
|
|
|
|
default : break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-10-28 10:19:18 +00:00
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
|
if (ok)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = false;
|
1998-02-13 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
1999-07-16 14:59:11 +00:00
|
|
|
|
|
2009-12-09 11:19:59 +00:00
|
|
|
|
/*
|
1999-07-16 14:59:11 +00:00
|
|
|
|
#define BIT31 (1L<<31)
|
|
|
|
|
#define MSK31 (~BIT31)
|
|
|
|
|
|
|
|
|
|
real TDongle::residual_assist(int index, bool lire) const
|
|
|
|
|
{
|
|
|
|
|
real imp;
|
|
|
|
|
if (index >= 0 && index < MAX_DONGLE_ASSIST)
|
|
|
|
|
{
|
|
|
|
|
imp = (_assist[index] & MSK31) / 100.0;
|
|
|
|
|
if (lire)
|
|
|
|
|
{ imp *= 1936.27; imp.round(-2); }
|
|
|
|
|
}
|
|
|
|
|
return imp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::can_require_assist(int index) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (index >= 0 && index < MAX_DONGLE_ASSIST)
|
|
|
|
|
{
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
if (oggi == _last_assist)
|
|
|
|
|
ok = (_assist[index] & BIT31) == 0;
|
|
|
|
|
else
|
|
|
|
|
ok = oggi > _last_assist;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::require_assist(int index, real imp, bool lire)
|
|
|
|
|
{
|
|
|
|
|
imp *= 100;
|
|
|
|
|
if (lire) { imp /= 1936.27; imp.round(2); }
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool ok = false;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (imp > ZERO)
|
|
|
|
|
{
|
|
|
|
|
if (can_require_assist(index))
|
|
|
|
|
{
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
if (oggi > _last_assist)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < MAX_DONGLE_ASSIST; i++)
|
|
|
|
|
_assist[index] &= MSK31;
|
|
|
|
|
_last_assist = oggi;
|
|
|
|
|
}
|
|
|
|
|
_assist[index] &= MSK31;
|
|
|
|
|
_assist[index] += imp.integer();
|
|
|
|
|
_assist[index] |= BIT31;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = burn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDongle::pay_assist(int index, real imp, bool lire)
|
|
|
|
|
{
|
|
|
|
|
bool ok = imp > ZERO;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
imp *= 100;
|
|
|
|
|
if (lire) { imp /= 1936.27; imp.round(2); }
|
|
|
|
|
|
|
|
|
|
unsigned long old_bit31 = _assist[index] & BIT31;
|
|
|
|
|
_assist[index] &= MSK31;
|
|
|
|
|
_assist[index] -= imp.integer();
|
|
|
|
|
_assist[index] |= old_bit31;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_dirty = true;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
ok = burn();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
2004-03-12 15:08:44 +00:00
|
|
|
|
}
|
2009-12-09 11:19:59 +00:00
|
|
|
|
*/
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
|
|
|
|
const TString_array& TDongle::info() const
|
|
|
|
|
{
|
|
|
|
|
if (_info.items() == 0)
|
|
|
|
|
{
|
|
|
|
|
TScanner scanner("campo.aut");
|
|
|
|
|
for (int aut = 0; ; aut++)
|
|
|
|
|
{
|
2008-10-22 14:17:48 +00:00
|
|
|
|
const TString& row = scanner.line();
|
2007-01-25 15:42:56 +00:00
|
|
|
|
if (row.blank())
|
2006-12-13 16:22:33 +00:00
|
|
|
|
break;
|
2007-01-25 15:42:56 +00:00
|
|
|
|
|
2008-10-22 14:17:48 +00:00
|
|
|
|
TToken_string* tok = new TToken_string;
|
|
|
|
|
tok->strncpy(row, 3);
|
|
|
|
|
const TString& name = row.mid(3);
|
2007-01-25 15:42:56 +00:00
|
|
|
|
if (name.full())
|
2008-10-22 14:17:48 +00:00
|
|
|
|
*tok << dictionary_translate(name);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
((TString_array&)_info).add(tok);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word TDongle::module_name2code(const char* mod) const
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
if (mod && *mod && xvt_str_compare_ignoring_case(mod, "sy") != 0)
|
|
|
|
|
{
|
|
|
|
|
if (real::is_natural(mod))
|
|
|
|
|
{
|
|
|
|
|
i = atoi(mod);
|
|
|
|
|
// Trasforma i numeri da 74 a 77 nei codici da M74AUT a M77AUT
|
|
|
|
|
if (i >= 74 && i <= 77)
|
|
|
|
|
i += M74AUT-74;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const TString_array& modinfo = info();
|
|
|
|
|
for (i = modinfo.last(); i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (modinfo.row(i).starts_with(mod, true))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return word(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TDongle::module_code2name(word mod) const
|
|
|
|
|
{
|
|
|
|
|
const TString_array& modinfo = info();
|
|
|
|
|
if (mod < modinfo.items())
|
|
|
|
|
return modinfo.row(mod).left(2);
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TDongle::module_code2desc(word mod) const
|
|
|
|
|
{
|
|
|
|
|
const TString_array& modinfo = info();
|
2009-05-20 15:36:38 +00:00
|
|
|
|
return mod < modinfo.items() ? modinfo.row(mod).mid(3) : EMPTY_STRING;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-23 11:37:37 +00:00
|
|
|
|
const TString& TDongle::module_name2desc(const char* mod) const
|
|
|
|
|
{
|
|
|
|
|
const word cod = module_name2code(mod);
|
|
|
|
|
if (cod == 0)
|
|
|
|
|
{
|
|
|
|
|
if (xvt_str_compare_ignoring_case(mod, "sy") == 0)
|
|
|
|
|
return get_tmp_string() = TR("Sistema");
|
|
|
|
|
}
|
|
|
|
|
return module_code2desc(cod);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool TDongle::shown(word code) const
|
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
bool yes = code < ENDAUT;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (yes)
|
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
yes = _shown[code];
|
|
|
|
|
if (!yes) // Puo' voler dire "nascosto" ma anche "non ho mai controllato"
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2007-06-01 09:44:03 +00:00
|
|
|
|
const TString4 mod = module_code2name(code);
|
|
|
|
|
yes = mod.not_empty();
|
2009-05-20 15:36:38 +00:00
|
|
|
|
if (yes && code > BAAUT && code < ENDAUT)
|
2007-06-01 09:44:03 +00:00
|
|
|
|
{
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TAuto_token_string ee = ini_get_string(CONFIG_GENERAL, mod, "OEM"); // Modern OEM handling
|
|
|
|
|
if (ee.full())
|
|
|
|
|
yes = ee.get_pos(oem()) >= 0;
|
2007-06-01 09:44:03 +00:00
|
|
|
|
}
|
|
|
|
|
if (yes)
|
|
|
|
|
((TBit_array&)_shown).set(code); // Setto il flag di visibilta' per la prossima volta
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return yes;
|
|
|
|
|
}
|
2009-10-28 10:19:18 +00:00
|
|
|
|
|
|
|
|
|
bool TDongle::demo() const
|
|
|
|
|
{ return hardware() == _dongle_unknown && type() == _no_dongle; }
|
2010-01-04 10:08:35 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// TEnigma_machine
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#define DNINST_PATH "setup/dninst.zip"
|
|
|
|
|
|
|
|
|
|
class TEnigma_machine : public TObject
|
|
|
|
|
{
|
|
|
|
|
TScanner* _scan;
|
|
|
|
|
int _year_assist;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void init_key(char key[8]) const;
|
|
|
|
|
bool decode_string(const TString& datain, TString& dataout) const;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual bool ok() const { return _scan != NULL && !_scan->eof(); }
|
|
|
|
|
|
|
|
|
|
bool line(TString& data);
|
|
|
|
|
bool find_serno(long serno);
|
|
|
|
|
int year_assist() const { return _year_assist; }
|
|
|
|
|
|
|
|
|
|
TEnigma_machine();
|
|
|
|
|
~TEnigma_machine();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void TEnigma_machine::init_key(char key[8]) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
key[i] = 'A' + ::rand() % 26;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEnigma_machine::decode_string(const TString& datain, TString& dataout) const
|
|
|
|
|
{
|
|
|
|
|
dataout.cut(0);
|
|
|
|
|
if (datain.not_empty())
|
|
|
|
|
{
|
|
|
|
|
char* tmp = dataout.get_buffer(datain.len());
|
|
|
|
|
char key[8]; init_key(key);
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; datain[i]; i++)
|
|
|
|
|
tmp[i] = datain[i] - (i < 8 ? key[i] : tmp[i - 8]);
|
|
|
|
|
tmp[i] = '\0';
|
|
|
|
|
}
|
|
|
|
|
return dataout.full();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEnigma_machine::line(TString& data)
|
|
|
|
|
{ return _scan != NULL ? decode_string(_scan->line(), data) : false; }
|
|
|
|
|
|
|
|
|
|
bool TEnigma_machine::find_serno(long serno)
|
|
|
|
|
{
|
|
|
|
|
if (serno == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
TToken_string row(80, ';');
|
|
|
|
|
if (_year_assist > 2100)
|
|
|
|
|
{
|
|
|
|
|
TString8 para; para << '[' << serno << ']';
|
|
|
|
|
while (line(row))
|
|
|
|
|
{
|
|
|
|
|
if (row == para)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while (line(row))
|
|
|
|
|
{
|
|
|
|
|
if (row.get_long(0) == serno)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEnigma_machine::TEnigma_machine()
|
|
|
|
|
: _scan(NULL), _year_assist(0)
|
|
|
|
|
{
|
|
|
|
|
if (fexist(DNINST_PATH))
|
|
|
|
|
{
|
|
|
|
|
_scan = new TScanner(DNINST_PATH);
|
|
|
|
|
::srand(883);
|
|
|
|
|
TString4 l1; line(l1);
|
|
|
|
|
_year_assist = atoi(l1);
|
|
|
|
|
::srand(_year_assist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEnigma_machine::~TEnigma_machine()
|
|
|
|
|
{
|
|
|
|
|
if (_scan != NULL)
|
|
|
|
|
delete _scan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Tdninst::assistance_year2solar(int ay) const
|
2010-01-18 15:40:27 +00:00
|
|
|
|
{ return (ay/1000)*1000 + (ay%1000)/10; }
|
2010-01-04 10:08:35 +00:00
|
|
|
|
|
2010-01-18 15:40:27 +00:00
|
|
|
|
int Tdninst::parse_date(const TString& line, TString& key, TDate& datascad) const
|
2010-01-04 10:08:35 +00:00
|
|
|
|
{
|
|
|
|
|
const int equal = line.find('=');
|
|
|
|
|
if (equal > 0 && equal <= 16)
|
|
|
|
|
{
|
|
|
|
|
key = line.left(equal); key.trim();
|
|
|
|
|
TString16 strdate = line.mid(equal+1, 16); strdate.trim();
|
2010-01-18 15:40:27 +00:00
|
|
|
|
if (strdate.empty())
|
|
|
|
|
{
|
|
|
|
|
datascad = TODAY; // Mettiamo una data valida comunque
|
|
|
|
|
return key.full() ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-04 10:08:35 +00:00
|
|
|
|
int d, m, y;
|
|
|
|
|
if (sscanf(strdate, "%2d-%2d-%4d", &d, &m, &y) == 3)
|
|
|
|
|
{
|
|
|
|
|
datascad = TDate(d, m, y);
|
2010-01-18 15:40:27 +00:00
|
|
|
|
return datascad.ok() ? 2 : 0;
|
2010-01-04 10:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-18 15:40:27 +00:00
|
|
|
|
return 0;
|
2010-01-04 10:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Tdninst::test_cmdline(const TString& cmdline, bool key_must_exist, TString& msg) const
|
|
|
|
|
{
|
|
|
|
|
msg.cut(0);
|
|
|
|
|
|
|
|
|
|
const TDongle& don = dongle();
|
|
|
|
|
const long serno = don.number();
|
|
|
|
|
if (serno == 0)
|
|
|
|
|
{
|
|
|
|
|
if (is_power_reseller(true))
|
|
|
|
|
return 0; // Solo chiavi per uso interno aga
|
|
|
|
|
msg = TR("Chiave di sviluppo non autorizzata");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString4 strmod = cmdline.left(2);
|
2010-02-09 10:11:25 +00:00
|
|
|
|
if (!key_must_exist) // Le personalizzazioni non hanno un modulo vero e proprio
|
|
|
|
|
{
|
|
|
|
|
const int space_pos = cmdline.find(' ');
|
|
|
|
|
if (space_pos < 0 || space_pos == 3)
|
|
|
|
|
{
|
|
|
|
|
const word codmod = don.module_name2code(strmod);
|
|
|
|
|
if (codmod == BAAUT)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/*if (!don.active(codmod))
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Modulo non attivo sulla chiave: ") << strmod;
|
|
|
|
|
return 2;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
2010-01-04 10:08:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
const int solar_year = oggi.year();
|
|
|
|
|
const int dongle_ass = don.year_assist();
|
|
|
|
|
const int dongle_year = assistance_year2solar(dongle_ass);
|
|
|
|
|
if (solar_year - dongle_year >= 2)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Anno di assitenza non valido sulla chiave: ") << dongle_year;
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEnigma_machine em;
|
|
|
|
|
const int dninst_ass = em.year_assist();
|
|
|
|
|
if (dongle_ass > dninst_ass)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("File dninst.zip obsoleto");
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bFound = false;
|
|
|
|
|
if (dninst_ass > 2100)
|
|
|
|
|
{
|
|
|
|
|
if (em.find_serno(serno))
|
|
|
|
|
{
|
|
|
|
|
TString80 dninst_line;
|
|
|
|
|
TString16 key;
|
|
|
|
|
TDate datascad;
|
|
|
|
|
while (em.line(dninst_line))
|
|
|
|
|
{
|
|
|
|
|
if (dninst_line.empty() || dninst_line.starts_with("["))
|
|
|
|
|
break; // Fine file o paragrafo
|
|
|
|
|
|
|
|
|
|
if (parse_date(dninst_line, key, datascad))
|
|
|
|
|
{
|
|
|
|
|
const bool scaduto = datascad < oggi;
|
|
|
|
|
if (key == "*")
|
|
|
|
|
{
|
|
|
|
|
if (scaduto)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Chiave scaduta il ") << datascad;
|
|
|
|
|
return 7;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if (key == cmdline)
|
|
|
|
|
{
|
|
|
|
|
bFound = true;
|
|
|
|
|
if (scaduto)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Applicazione scaduta il ") << datascad;
|
|
|
|
|
return 8;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if (key == strmod)
|
|
|
|
|
{
|
|
|
|
|
if (scaduto)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Modulo scaduto il ") << datascad;
|
|
|
|
|
return 9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TToken_string dninst_line(80, ';');
|
|
|
|
|
while (em.line(dninst_line))
|
|
|
|
|
{
|
|
|
|
|
bFound = dninst_line.get_long(0) == serno;
|
|
|
|
|
if (bFound)
|
|
|
|
|
{
|
|
|
|
|
if (dninst_line.get_pos(strmod) > 0)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Modulo non attivo in dninst.zip : ") << strmod;
|
|
|
|
|
return 5;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bFound && key_must_exist)
|
|
|
|
|
{
|
|
|
|
|
msg << TR("Impossibile trovare ") << cmdline;
|
|
|
|
|
return 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-26 11:06:08 +00:00
|
|
|
|
bool Tdninst::can_I_run(const bool is_personal_program) const
|
2010-01-04 10:08:35 +00:00
|
|
|
|
{
|
|
|
|
|
TFilename cmdline = main_app().argv(0);
|
|
|
|
|
cmdline = cmdline.name_only();
|
|
|
|
|
if (cmdline.starts_with("ba", true))
|
|
|
|
|
return true;
|
|
|
|
|
|
2010-01-26 11:06:08 +00:00
|
|
|
|
const bool me = is_personal_program || cmdline.len()>3;
|
2010-01-04 10:08:35 +00:00
|
|
|
|
const char* option = main_app().argc() > 1 ? main_app().argv(1) : "";
|
|
|
|
|
if (*option == '-' && isdigit(*(option+1)))
|
|
|
|
|
cmdline << ' ' << option;
|
|
|
|
|
cmdline.lower();
|
|
|
|
|
TString msg;
|
|
|
|
|
return test_cmdline(cmdline, me, msg) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Tdninst::find_killed(TToken_string& kill_list) const
|
|
|
|
|
{
|
|
|
|
|
kill_list.cut(0);
|
|
|
|
|
|
|
|
|
|
const int serno = dongle().number();
|
|
|
|
|
if (serno == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool good = false;
|
|
|
|
|
TEnigma_machine em;
|
|
|
|
|
if (em.ok())
|
|
|
|
|
{
|
|
|
|
|
if (em.year_assist() > 2100)
|
|
|
|
|
{
|
|
|
|
|
TToken_string l(80, '=');
|
|
|
|
|
good = em.find_serno(serno);
|
|
|
|
|
if (good)
|
|
|
|
|
{
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
TString16 str;
|
|
|
|
|
TDate ds;
|
|
|
|
|
while (em.line(l))
|
|
|
|
|
{
|
|
|
|
|
if (l.empty() || l[0] == '[')
|
|
|
|
|
break;
|
|
|
|
|
if (parse_date(l, str, ds) && ds < oggi)
|
|
|
|
|
kill_list.add(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TToken_string l(80, ';');
|
|
|
|
|
while (em.line(l))
|
|
|
|
|
{
|
|
|
|
|
if (l.get_long(0) == serno)
|
|
|
|
|
{
|
|
|
|
|
const int semicolon = l.find(l.separator());
|
|
|
|
|
if (semicolon > 0)
|
|
|
|
|
{
|
|
|
|
|
kill_list = l.mid(semicolon+1);
|
|
|
|
|
kill_list.lower();
|
|
|
|
|
kill_list.replace(l.separator(), kill_list.separator());
|
|
|
|
|
}
|
|
|
|
|
good = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return good;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tdninst::Tdninst() : _year_assist(0)
|
|
|
|
|
{
|
|
|
|
|
TEnigma_machine s;
|
|
|
|
|
_year_assist = s.year_assist(); // 2091 or 2101?
|
|
|
|
|
}
|