Pippe varie
git-svn-id: svn://10.65.10.50/trunk@5305 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
f8b98a8f16
commit
b3238e63ec
17
ba/ba0.cpp
17
ba/ba0.cpp
@ -707,17 +707,12 @@ int TSubmenu::find_string(const char* str) const
|
||||
for (int i = 0; i < items(); i++)
|
||||
{
|
||||
const TMenuitem& mi = item(i);
|
||||
if (mi.enabled() && mi.is_program())
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
caption = item(i).caption();
|
||||
caption.upper();
|
||||
found = caption.find(str) >= 0;
|
||||
}
|
||||
if (found)
|
||||
return i;
|
||||
}
|
||||
caption = item(i).caption();
|
||||
caption.upper();
|
||||
const bool match = caption.find(str) >= 0;
|
||||
found = match && mi.is_program() && mi.enabled();
|
||||
if (found)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
677
ba/ba1500.cpp
677
ba/ba1500.cpp
@ -6,7 +6,7 @@
|
||||
#include <utility.h>
|
||||
#include <urldefid.h>
|
||||
|
||||
#include <extcdecl.h>
|
||||
#include <hlapi_c.h>
|
||||
|
||||
#include "ba1.h"
|
||||
#include "ba1500.h"
|
||||
@ -19,18 +19,273 @@
|
||||
#define K1 0x4500
|
||||
#define LBYTEMASK 0x00FF
|
||||
#define UBYTEMASK 0xFF00
|
||||
#define MAXAUT 49
|
||||
|
||||
enum KeyType { _user_key, _aga_key, _prassi_key, _procom_key};
|
||||
|
||||
#define BITTEST(w,p) (((w) & (0x0001 << (p))) != 0)
|
||||
#define BITSET(w,p,v) ((v) ? ((w) |= (0x0001 << (p))) : ((w) &= (~(0x0001 << (p)))))
|
||||
|
||||
enum KeyType { _user_key, _aga_key, _prassi_key, _procom_key};
|
||||
|
||||
class TDongle : public TObject
|
||||
{
|
||||
word _serno;
|
||||
KeyType _type;
|
||||
word _eprom[64];
|
||||
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
word _port;
|
||||
#endif
|
||||
|
||||
TBit_array _module;
|
||||
bool _dirty;
|
||||
|
||||
protected:
|
||||
bool already_programmed() const;
|
||||
bool write_octect(word reg, word data[4]) const;
|
||||
|
||||
public:
|
||||
bool login();
|
||||
bool logout();
|
||||
|
||||
word number() const { return _serno; }
|
||||
bool ok() const { return _serno != 0xFFFF; }
|
||||
|
||||
void garble(word data[4]) const;
|
||||
|
||||
KeyType type() const { return _type; }
|
||||
|
||||
bool active(word module) const { return _module[module]; }
|
||||
void activate(word module, bool on = TRUE) { _module.set(module, on); _dirty = TRUE; }
|
||||
void deactivate(word module) { activate(module, FALSE); }
|
||||
|
||||
bool dirty() const { return _dirty; }
|
||||
bool burn();
|
||||
|
||||
TDongle();
|
||||
virtual ~TDongle() { logout(); }
|
||||
};
|
||||
|
||||
TDongle::TDongle()
|
||||
: _type(_user_key), _serno(0xFFFF), _dirty(FALSE)
|
||||
{
|
||||
memset(_eprom, 0, sizeof(_eprom));
|
||||
}
|
||||
|
||||
void TDongle::garble(word k[4]) const
|
||||
{
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(_port, ModAd);
|
||||
K_EYE(_port, k, HLBLOCK);
|
||||
HL_OFF(_port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST k, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool TDongle::already_programmed() const
|
||||
{
|
||||
word data[4];
|
||||
memcpy(data, &_eprom[60], sizeof(data));
|
||||
garble(data);
|
||||
|
||||
if (data[0] != 0xFACE)
|
||||
return FALSE;
|
||||
|
||||
if (data[1] != _serno)
|
||||
return FALSE;
|
||||
|
||||
const TDate today(TODAY);
|
||||
const long& giulio = (const long&)data[2];
|
||||
const long yyyymmdd = today.julian2date(giulio);
|
||||
const TDate d(yyyymmdd);
|
||||
if (d.year() < 1997 || d.year() > 2997)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TDongle::login()
|
||||
{
|
||||
bool ok = TRUE;
|
||||
_type = _user_key;
|
||||
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
if (Hl_Port(AGAADR) != 0)
|
||||
_type = _aga_key;
|
||||
else
|
||||
if (Hl_Port(PRASSIADR) != 0)
|
||||
_type = _prassi_key;
|
||||
else
|
||||
if (Hl_Port(PROCOMADR) != 0)
|
||||
_type = _prcom_key;
|
||||
_port = Hl_Port(USERADR);
|
||||
#else
|
||||
HL_LOGOUT();
|
||||
if (HL_LOGIN(AGAADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK)
|
||||
_type = _aga_key;
|
||||
else
|
||||
{
|
||||
HL_LOGOUT();
|
||||
if (HL_LOGIN(PRASSIADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK)
|
||||
_type = _prassi_key;
|
||||
else
|
||||
{
|
||||
HL_LOGOUT();
|
||||
if (HL_LOGIN(PROCOMADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK)
|
||||
_type = _procom_key;
|
||||
}
|
||||
}
|
||||
HL_LOGOUT();
|
||||
ok = HL_LOGIN(USERADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK;
|
||||
|
||||
if (ok)
|
||||
{
|
||||
HL_READBL((char*)_eprom);
|
||||
|
||||
word data[4];
|
||||
memcpy(data, _eprom, sizeof(data));
|
||||
garble(data);
|
||||
|
||||
if (data[0] == 0xFAE8)
|
||||
_serno = data[1];
|
||||
else
|
||||
ok = FALSE;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
if (_serno > 0)
|
||||
{
|
||||
_module.reset();
|
||||
_module.set(0, TRUE);
|
||||
|
||||
const int last_word = already_programmed() ? 12 : 4;
|
||||
for (int i = 0; i < last_word; i += 4)
|
||||
{
|
||||
word data[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;
|
||||
for (int b = 15; b >= 0; b--)
|
||||
{
|
||||
if (BITTEST(parola, b))
|
||||
{
|
||||
const word bit = i * 12 + j * 16 + b;
|
||||
_module.set(bit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_module.set(MAX_AUT-1);
|
||||
_module.set();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TDongle::logout()
|
||||
{
|
||||
HL_LOGOUT();
|
||||
_serno = 0xFFFF;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TDongle::write_octect(word reg, word k[4]) const
|
||||
{
|
||||
int err = STATUS_OK;
|
||||
for (word r = 0; r < 4; r++)
|
||||
{
|
||||
const word address = reg+r;
|
||||
err = HL_WRITE(address, k[r]);
|
||||
if (err != STATUS_OK)
|
||||
{
|
||||
error_box("Errore di scrittura sul registro %u", address);
|
||||
break;
|
||||
}
|
||||
#ifdef DBG
|
||||
word test;
|
||||
HL_READ(address, (int*)&test);
|
||||
if (test != k[r])
|
||||
error_box("Errore di scrittura sul registro %u", address);
|
||||
#endif
|
||||
}
|
||||
return err == STATUS_OK;
|
||||
}
|
||||
|
||||
bool TDongle::burn()
|
||||
{
|
||||
if (!dirty() || _serno == 0 || _serno == 0xFFFF)
|
||||
return FALSE;
|
||||
|
||||
word data[4];
|
||||
|
||||
const TDate today(TODAY);
|
||||
const bool already = already_programmed();
|
||||
if (already)
|
||||
{
|
||||
memcpy(data, &_eprom[60], sizeof(data));
|
||||
garble(data);
|
||||
if (data[0] != 0xFACE)
|
||||
return error_box("Checksum error.");
|
||||
if (data[1] != _serno)
|
||||
return error_box("Bad serial number.");
|
||||
const long& val = (const long&)data[2];
|
||||
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] = 0xFACE;
|
||||
data[1] = _serno;
|
||||
long& val = (long&)data[2];
|
||||
val = today.date2julian();
|
||||
garble(data);
|
||||
write_octect(60, data);
|
||||
|
||||
word module = 0;
|
||||
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))
|
||||
BITSET(p, bit, TRUE);
|
||||
module++;
|
||||
}
|
||||
p ^= _serno;
|
||||
}
|
||||
data[3] = _serno;
|
||||
garble(data);
|
||||
write_octect(48 + 4*octect, data);
|
||||
}
|
||||
|
||||
_dirty = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TInformazione_moduli::TInformazione_moduli()
|
||||
{
|
||||
int mod = 0;
|
||||
char _buffer[256];
|
||||
TString s;
|
||||
TString s(256);
|
||||
TToken_string t;
|
||||
TString_array descs;
|
||||
|
||||
@ -38,14 +293,15 @@ TInformazione_moduli::TInformazione_moduli()
|
||||
ifstream in("prassi.aut");
|
||||
while (!in.eof() && in.good())
|
||||
{
|
||||
in.getline(_buffer, sizeof(_buffer),'\n');
|
||||
s = _buffer;
|
||||
in.getline(s.get_buffer(256), s.size());
|
||||
s.trim();
|
||||
if (s.empty()) break;
|
||||
if (s.empty())
|
||||
break;
|
||||
const int l = s.len();
|
||||
if (l > 2)
|
||||
{
|
||||
t = format("%-40s",(const char*)s.right(l-3));
|
||||
// t = format("%-40s", (const char*)s.right(l-3));
|
||||
t = format("%-40s", (const char*)s.mid(3));
|
||||
t.add(s.left(2));
|
||||
}
|
||||
else
|
||||
@ -54,10 +310,10 @@ TInformazione_moduli::TInformazione_moduli()
|
||||
_unassigned_modules++;
|
||||
}
|
||||
t.add(mod++);
|
||||
TString d(t.get(0));
|
||||
descs.add(d);
|
||||
d.upper();
|
||||
t.add(d, 0);
|
||||
s = t.get(0);
|
||||
descs.add(s);
|
||||
s.upper();
|
||||
t.add(s, 0);
|
||||
_infos.add(t);
|
||||
}
|
||||
|
||||
@ -70,14 +326,14 @@ TInformazione_moduli::TInformazione_moduli()
|
||||
TToken_string& riga = _infos.row(i);
|
||||
const int mod = riga.get_int(2);
|
||||
_index[mod] = i;
|
||||
const TString d(descs.row(mod).get(0));
|
||||
riga.add(d, 0);
|
||||
s = descs.row(mod).get(0);
|
||||
riga.add(s, 0);
|
||||
}
|
||||
}
|
||||
|
||||
const char * TInformazione_moduli::get_description_by_order(int index)
|
||||
{
|
||||
if (index>=0 && index<ENDAUT)
|
||||
if (index >= 0 && index < _infos.items())
|
||||
return _infos.row(index).get(0);
|
||||
else
|
||||
return "";
|
||||
@ -85,7 +341,7 @@ const char * TInformazione_moduli::get_description_by_order(int index)
|
||||
|
||||
const char * TInformazione_moduli::get_name_by_order(int index)
|
||||
{
|
||||
if (index>=0 && index<ENDAUT)
|
||||
if (index >= 0 && index < _infos.items())
|
||||
return _infos.row(index).get(1);
|
||||
else
|
||||
return "";
|
||||
@ -93,8 +349,8 @@ const char * TInformazione_moduli::get_name_by_order(int index)
|
||||
|
||||
int TInformazione_moduli::get_module_by_order(int index)
|
||||
{
|
||||
if (index>=0 && index<ENDAUT)
|
||||
return atoi(_infos.row(index).get(2));
|
||||
if (index >= 0 && index < _infos.items())
|
||||
return _infos.row(index).get_int(2);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
@ -108,42 +364,45 @@ const char * TInformazione_moduli::get_name(int module)
|
||||
int TInformazione_moduli::get_index(int module)
|
||||
{ return _index[module]; }
|
||||
|
||||
|
||||
class TError_application : public TApplication
|
||||
{
|
||||
TString _errmess;
|
||||
virtual bool create()
|
||||
{ fatal_box(_errmess); return FALSE; }
|
||||
public:
|
||||
TError_application(const char* err) : _errmess(err) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TAttivazione_moduli : public TApplication
|
||||
{
|
||||
TMask* _msk;
|
||||
TInformazione_moduli* _im;
|
||||
|
||||
KeyType _key_type;
|
||||
TDongle _dongle;
|
||||
word _serno;
|
||||
word _port;
|
||||
|
||||
protected:
|
||||
virtual bool create() ;
|
||||
virtual bool destroy() ;
|
||||
virtual bool use_files() const { return FALSE; }
|
||||
virtual bool menu(MENU_TAG);
|
||||
|
||||
void garble(word k[4]) const;
|
||||
void garble(word n, TString& str) const;
|
||||
word& serno() { return _serno; }
|
||||
|
||||
void generate_key();
|
||||
int build_sheet(bool on = TRUE);
|
||||
void build_key_column();
|
||||
|
||||
bool burn_dongle();
|
||||
|
||||
static void keyext(const TString & s, word * v);
|
||||
static bool user_hnd(TMask_field & f, KEY k);
|
||||
static void encode_second_key();
|
||||
|
||||
static bool user_hnd(TMask_field & f, KEY k);
|
||||
static bool serno_hnd(TMask_field & f, KEY k);
|
||||
static bool decode_hnd(TMask_field & f, KEY k);
|
||||
static bool activate_hnd(TMask_field & f, KEY k);
|
||||
static bool k_notify(TSheet_field & f, int r, KEY k);
|
||||
|
||||
public:
|
||||
TAttivazione_moduli() : _msk(NULL) { _key_type = _user_key;}
|
||||
TAttivazione_moduli() : _msk(NULL) { }
|
||||
};
|
||||
|
||||
|
||||
@ -152,24 +411,112 @@ HIDDEN TAttivazione_moduli& app() { return (TAttivazione_moduli &)main_app(); }
|
||||
int TAttivazione_moduli::build_sheet(bool on)
|
||||
{
|
||||
int nmod = 0;
|
||||
TSheet_field& sf = (TSheet_field&) _msk->field(F_MODULI);
|
||||
for (int i = 0; i < ENDAUT; i++)
|
||||
TSheet_field& sf = (TSheet_field&)_msk->field(F_MODULI);
|
||||
for (int i = 0; i < _im->items(); i++)
|
||||
{
|
||||
TString d( _im->get_description_by_order(i));
|
||||
if (d.trim().empty()) continue;
|
||||
const TFixed_string d(_im->get_description_by_order(i));
|
||||
if (d.blank())
|
||||
continue;
|
||||
TToken_string& riga = sf.row(i);
|
||||
riga = d;
|
||||
riga = d; riga.trim();
|
||||
const int module = _im->get_module_by_order(i);
|
||||
if (has_module(module, CHK_DONGLE) && on || module==0)
|
||||
|
||||
const bool ics = module == 0 || (on && _dongle.active(module));
|
||||
if (ics)
|
||||
{
|
||||
riga.add("X");
|
||||
if (module != 0) nmod++;
|
||||
} else riga.add(" ");
|
||||
if (module != 0)
|
||||
nmod++;
|
||||
}
|
||||
else
|
||||
riga.add(" ");
|
||||
riga.add(module);
|
||||
}
|
||||
return nmod;
|
||||
}
|
||||
|
||||
void TAttivazione_moduli::garble(word k[4]) const
|
||||
{
|
||||
_dongle.garble(k);
|
||||
}
|
||||
|
||||
void TAttivazione_moduli::garble(word n, TString& str) const
|
||||
{
|
||||
const TDate today(TODAY);
|
||||
const long val = today.date2julian();
|
||||
|
||||
word data[4];
|
||||
data[0] = word(_msk->get_int(F_SN));
|
||||
data[1] = n;
|
||||
data[2] = word(val >> 16);
|
||||
data[3] = word(val & 0xFFFF);
|
||||
garble(data);
|
||||
str.format("%04X%04X", data[0], data[1]);
|
||||
}
|
||||
|
||||
void TAttivazione_moduli::build_key_column()
|
||||
{
|
||||
TSheet_field& sf = (TSheet_field&)_msk->field(F_MODULI);
|
||||
sf.enable_column(F_KEY, FALSE);
|
||||
for (int i = sf.items()-1; i >= 0; i--)
|
||||
{
|
||||
TToken_string& riga = sf.row(i);
|
||||
TString16 str;
|
||||
int module = riga.get_int(2);
|
||||
garble(module, str);
|
||||
riga.add(str, 3);
|
||||
}
|
||||
}
|
||||
|
||||
bool TAttivazione_moduli::burn_dongle()
|
||||
{
|
||||
bool ok = _dongle.type() == _user_key;
|
||||
|
||||
if (ok)
|
||||
{
|
||||
TString16 str, key;
|
||||
|
||||
TSheet_field& sf = (TSheet_field&)_msk->field(F_MODULI);
|
||||
for (int i = 0; i < sf.items(); i++)
|
||||
{
|
||||
TToken_string& riga = sf.row(i);
|
||||
key = riga.get(3); key.trim();
|
||||
if (key.not_empty())
|
||||
{
|
||||
const int module = riga.get_int(2);
|
||||
garble(module, str);
|
||||
if (key == str)
|
||||
{
|
||||
if (!_dongle.active(module) &&
|
||||
yesno_box("Confermare l'attivazione del modulo %d:\n%s",
|
||||
module, riga.get(0)))
|
||||
{
|
||||
_dongle.activate(module);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_dongle.active(module) &&
|
||||
yesno_box("Confermare la disattivazione del modulo %d:\n%s",
|
||||
module, riga.get(0)))
|
||||
{
|
||||
_dongle.deactivate(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_dongle.dirty())
|
||||
{
|
||||
ok = _dongle.burn();
|
||||
if (!ok)
|
||||
error_box("Impossibile riprogrammare la chiave");
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void TAttivazione_moduli::generate_key()
|
||||
{
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
@ -183,47 +530,32 @@ void TAttivazione_moduli::generate_key()
|
||||
HL_OFF(_port);
|
||||
INT_ON();
|
||||
#else
|
||||
int ud[4];
|
||||
HL_READ(48, &ud[0]);
|
||||
HL_READ(49, &ud[1]);
|
||||
HL_READ(50, &ud[2]);
|
||||
HL_READ(51, &ud[3]);
|
||||
word ud[4];
|
||||
HL_READ(48, (int*)&ud[0]);
|
||||
HL_READ(49, (int*)&ud[1]);
|
||||
HL_READ(50, (int*)&ud[2]);
|
||||
HL_READ(51, (int*)&ud[3]);
|
||||
#endif
|
||||
|
||||
int nmod;
|
||||
|
||||
_msk->set(F_K2, format("%04X%04X%04X%04X", ud[0], ud[1], ud[2], ud[3]));
|
||||
nmod = build_sheet();
|
||||
_serno = SerNo;
|
||||
ud[0] = _serno;
|
||||
ud[0] = _dongle.number();
|
||||
ud[1] = K1 | (nmod & LBYTEMASK);
|
||||
long & l = (long &) ud[2];
|
||||
TDate d(TODAY);
|
||||
|
||||
l = d.year()*10000L + d.month()*100L + d.day();
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(_port, ModAd);
|
||||
K_EYE(_port, (unsigned char *) ud, HLBLOCK);
|
||||
HL_OFF(_port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST &ud[0], HLBLOCK);
|
||||
#endif
|
||||
garble(ud);
|
||||
_msk->set(F_K1, format("%04X%04X%04X%04X", ud[0], ud[1], ud[2], ud[3]));
|
||||
_msk->set(F_SN, SerNo);
|
||||
_msk->set(F_DT, d.string());
|
||||
_msk->set(F_SN, _dongle.number());
|
||||
_msk->set(F_DT, d);
|
||||
}
|
||||
|
||||
int hexdigit(char c)
|
||||
{
|
||||
static char s[] = "0123456789ABCDEF";
|
||||
int i = strlen(s);
|
||||
|
||||
while (i-- >= 0)
|
||||
if (s[i] == c)
|
||||
break;
|
||||
return i;
|
||||
return c >= 'A' ? (c - 'A' + 10) : (c - '0');
|
||||
}
|
||||
|
||||
void TAttivazione_moduli::keyext(const TString& s, word * val)
|
||||
@ -242,45 +574,32 @@ void TAttivazione_moduli::keyext(const TString& s, word * val)
|
||||
bool TAttivazione_moduli::user_hnd(TMask_field & f, KEY k)
|
||||
{
|
||||
const TString16 k4(f.get());
|
||||
if (!f.to_check(k) || k4.empty()) return TRUE;
|
||||
if (!f.to_check(k) || k4.empty())
|
||||
return TRUE;
|
||||
TMask & m = f.mask();
|
||||
word ud1[4], ud2[4], port = app()._port;
|
||||
word ud1[4], ud2[4];
|
||||
const TString16 k3(m.get(F_K3));
|
||||
|
||||
keyext(k3, ud1);
|
||||
keyext(k4, ud2);
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(port, ModAd);
|
||||
K_EYE(port, (unsigned char *) ud1, HLBLOCK);
|
||||
HL_OFF(port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST ud1, HLBLOCK);
|
||||
#endif
|
||||
|
||||
app().garble(ud1);
|
||||
const long & l = (long &) ud1[0];
|
||||
TDate d(l), d1(TODAY);
|
||||
|
||||
d.addmonth(3);
|
||||
if (d < d1)
|
||||
return f.error_box("data non valida");
|
||||
if ((ud1[2] & UBYTEMASK) != K1 || ud1[3] != app()._serno)
|
||||
if ((ud1[2] & UBYTEMASK) != K1 || ud1[3] != app().serno())
|
||||
return f.error_box("primo codice errato");
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(port, ModAd);
|
||||
K_EYE(port, (unsigned char *) ud2, HLBLOCK);
|
||||
HL_OFF(port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST ud2, HLBLOCK);
|
||||
#endif
|
||||
for (int i = 0; i < 4; i++) ud2[i] ^= app()._serno;
|
||||
|
||||
app().garble(ud2);
|
||||
for (int i = 0; i < 4; i++) ud2[i] ^= app().serno();
|
||||
if (ud2[3] != 0)
|
||||
return f.error_box("secondo codice errato");
|
||||
TSheet_field& sf = (TSheet_field&) m.field(F_MODULI);
|
||||
const int un = app()._im->unassigned();
|
||||
for (i = un; i < ENDAUT; i++)
|
||||
for (i = un; i < MAX_AUT; i++)
|
||||
{
|
||||
const int af = app()._im->get_module_by_order(i) - 1;
|
||||
if (af < 0) continue;
|
||||
@ -291,9 +610,9 @@ bool TAttivazione_moduli::user_hnd(TMask_field & f, KEY k)
|
||||
{
|
||||
keyext(k4, ud2);
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
word port = app()._dongle.port();
|
||||
INT_OFF();
|
||||
HL_ON(port, ModAd);
|
||||
HL_ON(port, ModAd);
|
||||
HL_WR(port, 48, ud2[0]);
|
||||
HL_WR(port, 49, ud2[1]);
|
||||
HL_WR(port, 50, ud2[2]);
|
||||
@ -311,16 +630,25 @@ bool TAttivazione_moduli::user_hnd(TMask_field & f, KEY k)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TAttivazione_moduli::serno_hnd(TMask_field& f, KEY k)
|
||||
{
|
||||
if (k == K_TAB && f.focusdirty())
|
||||
{
|
||||
app().build_key_column();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void TAttivazione_moduli::encode_second_key()
|
||||
{
|
||||
TMask * m = app()._msk;
|
||||
word ud1[4], ud2[4], port = app()._port;
|
||||
word ud1[4], ud2[4];
|
||||
int nmod = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++) ud2[i] = 0;
|
||||
TSheet_field& sf = (TSheet_field&) m->field(F_MODULI);
|
||||
const int un = app()._im->unassigned();
|
||||
for (i = un; i < ENDAUT; i++)
|
||||
for (i = un; i < MAX_AUT; i++)
|
||||
{
|
||||
const int af = app()._im->get_module_by_order(i) -1;
|
||||
if (af < 0) continue;
|
||||
@ -331,72 +659,53 @@ void TAttivazione_moduli::encode_second_key()
|
||||
nmod++;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 4; i++) ud2[i] ^= app()._serno;
|
||||
for (i = 0; i < 4; i++) ud2[i] ^= app().serno();
|
||||
|
||||
const TDate d(m->get(F_DT));
|
||||
long & l = (long &) ud1[0];
|
||||
|
||||
l = d.year()*10000L + d.month()*100L + d.day();
|
||||
ud1[2] = K1 | (nmod & UBYTEMASK);
|
||||
ud1[3] = app()._serno;
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(port, ModAd);
|
||||
K_EYE(port, (unsigned char *) ud1, HLBLOCK);
|
||||
K_EYE(port, (unsigned char *) ud2, HLBLOCK);
|
||||
HL_OFF(port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST ud1, HLBLOCK);
|
||||
HL_CODE(EYECAST ud2, HLBLOCK);
|
||||
#endif
|
||||
m->set(F_K4, format("%04X%04X%04X%04X", ud2[0], ud2[1], ud2[2], ud2[3]));
|
||||
ud1[3] = app().serno();
|
||||
|
||||
app().garble(ud1);
|
||||
m->set(F_K3, format("%04X%04X%04X%04X", ud1[0], ud1[1], ud1[2], ud1[3]));
|
||||
|
||||
app().garble(ud2);
|
||||
m->set(F_K4, format("%04X%04X%04X%04X", ud2[0], ud2[1], ud2[2], ud2[3]));
|
||||
}
|
||||
|
||||
bool TAttivazione_moduli::decode_hnd(TMask_field & f, KEY k)
|
||||
{
|
||||
const TString16 k2(f.get());
|
||||
if (!f.to_check(k) || k2.empty()) return TRUE;
|
||||
TMask & m = f.mask();
|
||||
word ud1[4], ud2[4], port = app()._port;
|
||||
if (!f.to_check(k) || k2.empty())
|
||||
return TRUE;
|
||||
|
||||
TMask& m = f.mask();
|
||||
word ud1[4], ud2[4];
|
||||
const TString16 k1(m.get(F_K1));
|
||||
|
||||
keyext(k1, ud1);
|
||||
keyext(k2, ud2);
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(port, USERADR);
|
||||
K_EYE(port, (unsigned char *) ud1, HLBLOCK);
|
||||
HL_OFF(port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST ud1, HLBLOCK);
|
||||
#endif
|
||||
|
||||
app().garble(ud1);
|
||||
long & l = (long &) ud1[2];
|
||||
const TDate d(l);
|
||||
app()._serno = ud1[0];
|
||||
app().serno() = ud1[0];
|
||||
if ((ud1[1] & UBYTEMASK) != K1)
|
||||
return f.error_box("primo codice errato");
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
INT_OFF();
|
||||
HL_ON(port, USERADR);
|
||||
K_EYE(port, (unsigned char *) ud2, HLBLOCK);
|
||||
HL_OFF(port);
|
||||
INT_ON();
|
||||
#else
|
||||
HL_CODE(EYECAST ud2, HLBLOCK);
|
||||
#endif
|
||||
for (int i = 0; i < 4; i++) ud2[i] ^= app()._serno;
|
||||
|
||||
app().garble(ud2);
|
||||
for (int i = 0; i < 4; i++) ud2[i] ^= app().serno();
|
||||
if (ud2[3] != 0)
|
||||
return f.error_box("secondo codice errato");
|
||||
m.set(F_SN, app()._serno);
|
||||
m.set(F_DT, d.string());
|
||||
m.set(F_SN, app().serno());
|
||||
m.set(F_DT, d);
|
||||
m.set(F_K3,k1);
|
||||
m.set(F_K4,k2);
|
||||
TSheet_field& sf = (TSheet_field&) m.field(F_MODULI);
|
||||
const int un = app()._im->unassigned();
|
||||
for (i = un; i < ENDAUT; i++)
|
||||
for (i = un; i < MAX_AUT; i++)
|
||||
{
|
||||
const int af = app()._im->get_module_by_order(i) -1;
|
||||
if (af < 0) continue;
|
||||
@ -423,9 +732,10 @@ bool TAttivazione_moduli::k_notify(TSheet_field& f, int r, KEY k)
|
||||
|
||||
bool TAttivazione_moduli::create()
|
||||
{
|
||||
if (user() != "PRASSI")
|
||||
return error_box("Utente non abilitato all'uso di questo programma");
|
||||
|
||||
bool ok = _dongle.login();
|
||||
if (!ok)
|
||||
return FALSE;
|
||||
|
||||
_im = new TInformazione_moduli;
|
||||
|
||||
disable_menu_item(M_FILE_NEW);
|
||||
@ -433,40 +743,12 @@ bool TAttivazione_moduli::create()
|
||||
disable_menu_item(M_FILE_PG_SETUP);
|
||||
|
||||
_msk = new TMask("ba1500a") ;
|
||||
#if XVT_OS == XVT_OS_SCOUNIX
|
||||
if (Hl_Port(AGAADR) != 0)
|
||||
_key_type = _aga_key;
|
||||
else
|
||||
if (Hl_Port(PRASSIADR) != 0)
|
||||
_key_type = _prassi_key;
|
||||
else
|
||||
if (Hl_Port(PROCOMADR) != 0)
|
||||
_key_type = _prcom_key;
|
||||
_port = Hl_Port(USERADR);
|
||||
#else
|
||||
HL_LOGOUT();
|
||||
if (HL_LOGIN(AGAADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK)
|
||||
_key_type = _aga_key;
|
||||
else
|
||||
{
|
||||
HL_LOGOUT();
|
||||
if (HL_LOGIN(PRASSIADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK)
|
||||
_key_type = _prassi_key;
|
||||
else
|
||||
{
|
||||
HL_LOGOUT();
|
||||
if (HL_LOGIN(PROCOMADR, DONT_CARE, REFKEY, VERKEY) == STATUS_OK)
|
||||
_key_type = _procom_key;
|
||||
}
|
||||
}
|
||||
HL_LOGOUT();
|
||||
HL_LOGIN(USERADR, DONT_CARE, REFKEY, VERKEY);
|
||||
#endif
|
||||
|
||||
TSheet_field& sf = (TSheet_field&) _msk->field(F_MODULI);
|
||||
const int un = _im->unassigned();
|
||||
sf.set_notify(k_notify);
|
||||
|
||||
switch (_key_type)
|
||||
switch (_dongle.type())
|
||||
{
|
||||
case _user_key:
|
||||
{
|
||||
@ -474,39 +756,36 @@ bool TAttivazione_moduli::create()
|
||||
_msk->disable(F_K2);
|
||||
_msk->set_handler(F_K4, user_hnd);
|
||||
generate_key();
|
||||
const int nm = sf.items();
|
||||
for (int i = 0; i < nm; i++)
|
||||
sf.disable_cell(i,1);
|
||||
sf.enable_column(F_ENABLE, FALSE);
|
||||
sf.enable_column(F_KEY, serno() != 0);
|
||||
}
|
||||
break;
|
||||
case _prassi_key:
|
||||
sf.disable_cell(_im->get_index(CMAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(ATAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(POAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(AFAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(TCAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(TMAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(VEAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(MGAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(ORAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(EFAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(DBAUT)-un,1);
|
||||
sf.disable_cell(_im->get_index(SVAUT)-un,1);
|
||||
case _aga_key:
|
||||
case _procom_key:
|
||||
case _prassi_key:
|
||||
{
|
||||
const int aut[] = { CMAUT, ATAUT, POAUT, AFAUT, TCAUT, TMAUT,
|
||||
VEAUT, MGAUT, ORAUT, EFAUT, DBAUT, SVAUT, -1 };
|
||||
for (int a = 0; aut[a] >= 0; a++)
|
||||
sf.disable_cell(_im->get_index(aut[a])-un,1);
|
||||
}
|
||||
case _aga_key:
|
||||
case _procom_key:
|
||||
{
|
||||
_msk->set_handler(F_K2, decode_hnd);
|
||||
_msk->disable(F_K3);
|
||||
_msk->disable(F_K4);
|
||||
_msk->disable(F_K4);
|
||||
_msk->enable(F_SN);
|
||||
|
||||
sf.sheet_mask().field(F_ENABLE).set_handler(activate_hnd);
|
||||
build_sheet(FALSE);
|
||||
for (int i = un; i < ENDAUT; i++)
|
||||
build_sheet(FALSE);
|
||||
build_key_column();
|
||||
|
||||
for (int i = un; i < MAX_AUT; i++)
|
||||
{
|
||||
const int af = _im->get_module_by_order(i);
|
||||
const int index = i-un;
|
||||
if (af == 0)
|
||||
sf.disable_cell(index,1);
|
||||
if (_key_type == _procom_key)
|
||||
if (_dongle.type() == _procom_key)
|
||||
sf.enable_cell(index,1,af>=40 && af<=46);
|
||||
else
|
||||
if (af>=40 && af<=46)
|
||||
@ -514,12 +793,11 @@ bool TAttivazione_moduli::create()
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
dispatch_e_menu(BAR_ITEM(1));
|
||||
return TRUE;
|
||||
}
|
||||
dispatch_e_menu(BAR_ITEM(1));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TAttivazione_moduli::destroy()
|
||||
@ -531,25 +809,24 @@ bool TAttivazione_moduli::destroy()
|
||||
|
||||
bool TAttivazione_moduli::menu(MENU_TAG)
|
||||
{
|
||||
_msk->run();
|
||||
KEY res = _msk->run();
|
||||
if (res == K_ENTER)
|
||||
burn_dongle();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int ba1500(int argc, char** argv)
|
||||
{
|
||||
// dipende dalla check_parameters fatta in main()
|
||||
TString user(user());
|
||||
if (user == "PRASSI")
|
||||
if (user() == "PRASSI")
|
||||
{
|
||||
TAttivazione_moduli a ;
|
||||
a.run(argc, argv, "Attivazione moduli");
|
||||
}
|
||||
else
|
||||
{
|
||||
TString err(80);
|
||||
err.format("L'utente %s non e' abilitato all'esecuzione di questo programma", (const char*)user);
|
||||
TError_application e(err);
|
||||
e.run(argc, argv, "Attivazione moduli");
|
||||
error_box("L'utente %s non e' abilitato all'esecuzione di questo programma", (const char*)user());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
10
ba/ba1500.h
10
ba/ba1500.h
@ -1,11 +1,16 @@
|
||||
#ifndef __BA1500_H__
|
||||
#define __BA1500_H__
|
||||
|
||||
#ifndef __STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
const word MAX_AUT = 48 * 3;
|
||||
|
||||
class TInformazione_moduli : public TObject
|
||||
{
|
||||
TString_array _infos;
|
||||
int _index[ENDAUT];
|
||||
int _index[MAX_AUT];
|
||||
int _unassigned_modules; // Moduli non assegnati, con descrizione vuota
|
||||
|
||||
public:
|
||||
@ -16,8 +21,9 @@ public:
|
||||
const char * get_name(int module);
|
||||
int get_index(int module);
|
||||
int unassigned() { return _unassigned_modules; }
|
||||
int items() const { return _infos.items(); }
|
||||
TInformazione_moduli() ;
|
||||
~TInformazione_moduli() {};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
27
ba/ba1500a.h
27
ba/ba1500a.h
@ -1,17 +1,18 @@
|
||||
#define F_K1 101
|
||||
#define F_K2 102
|
||||
#define F_K2A 103
|
||||
#define F_K2B 104
|
||||
#define F_K2C 105
|
||||
#define F_K3 106
|
||||
#define F_K4 107
|
||||
#define F_K4A 108
|
||||
#define F_K4B 109
|
||||
#define F_K4C 110
|
||||
#define F_SN 111
|
||||
#define F_DT 112
|
||||
#define F_MODULI 113
|
||||
#define F_K1 201
|
||||
#define F_K2 202
|
||||
#define F_K2A 203
|
||||
#define F_K2B 204
|
||||
#define F_K2C 205
|
||||
#define F_K3 206
|
||||
#define F_K4 207
|
||||
#define F_K4A 208
|
||||
#define F_K4B 209
|
||||
#define F_K4C 210
|
||||
#define F_SN 211
|
||||
#define F_DT 212
|
||||
#define F_MODULI 213
|
||||
|
||||
#define F_NOMEMOD 101
|
||||
#define F_ENABLE 102
|
||||
#define F_CODE 103
|
||||
#define F_KEY 104
|
||||
|
@ -7,7 +7,7 @@ BEGIN
|
||||
PROMPT -12 -1 ""
|
||||
END
|
||||
|
||||
BUTTON DLG_CANCEL 10 2
|
||||
BUTTON DLG_QUIT 10 2
|
||||
BEGIN
|
||||
PROMPT -22 -1 ""
|
||||
END
|
||||
@ -31,7 +31,7 @@ END
|
||||
STRING F_SN 5
|
||||
BEGIN
|
||||
PROMPT 56 1 "N.Serie "
|
||||
FLAGS "ZD"
|
||||
FLAGS "DUZ"
|
||||
END
|
||||
|
||||
DATE F_DT
|
||||
@ -54,12 +54,15 @@ END
|
||||
|
||||
SPREADSHEET F_MODULI 78
|
||||
BEGIN
|
||||
PROMPT 0 5 "Moduli"
|
||||
PROMPT 1 5 "Moduli"
|
||||
ITEM "Modulo@40"
|
||||
ITEM "Abilitato@C"
|
||||
ITEM "Codice"
|
||||
ITEM "Att."
|
||||
ITEM "Cod."
|
||||
ITEM "Chiave@8"
|
||||
END
|
||||
|
||||
ENDPAGE
|
||||
|
||||
ENDMASK
|
||||
|
||||
PAGE "Campo" -1 -1 60 11
|
||||
@ -72,21 +75,27 @@ END
|
||||
|
||||
BOOLEAN F_ENABLE
|
||||
BEGIN
|
||||
PROMPT 11 5 "Abilitato "
|
||||
PROMPT 11 4 "Abilitato "
|
||||
END
|
||||
|
||||
NUMBER F_CODE 3
|
||||
BEGIN
|
||||
PROMPT 1 7 "Codice "
|
||||
PROMPT 1 5 "Codice "
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
STRING F_KEY 8
|
||||
BEGIN
|
||||
PROMPT 1 6 "Chiave "
|
||||
FLAGS "U"
|
||||
END
|
||||
|
||||
BUTTON DLG_OK 9 2
|
||||
BUTTON DLG_OK 10 2
|
||||
BEGIN
|
||||
PROMPT -12 -1 ""
|
||||
END
|
||||
|
||||
BUTTON DLG_CANCEL 9 2
|
||||
BUTTON DLG_CANCEL 10 2
|
||||
BEGIN
|
||||
PROMPT -22 -1 ""
|
||||
END
|
||||
|
@ -78,8 +78,6 @@ bool TTab_application::user_destroy()
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Test Relapp
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -357,8 +355,6 @@ void TBenchmark_application::test_file_random()
|
||||
stop_test();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user